Skip to content

Commit c258d67

Browse files
committed
Merge pull request #45 from async-interop/single-on-error-handler
Changed onError() to setErrorHandler()
2 parents 6a13263 + 23284e5 commit c258d67

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/Loop.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,6 @@ public static function onSignal($signo, callable $callback, $data = null)
144144
return self::get()->onSignal($signo, $callback, $data);
145145
}
146146

147-
/**
148-
* Execute a callback when an error occurs.
149-
*
150-
* @param callable(\Throwable|\Exception $exception) $callback The callback to execute.
151-
*
152-
* @return string An identifier that can be used to cancel, enable or disable the watcher.
153-
*/
154-
public static function onError(callable $callback)
155-
{
156-
return self::get()->onError($callback);
157-
}
158-
159147
/**
160148
* Enable a watcher.
161149
*
@@ -222,6 +210,20 @@ public static function unreference($watcherId)
222210
self::get()->unreference($watcherId);
223211
}
224212

213+
/**
214+
* Set a callback to be executed when an error occurs.
215+
*
216+
* Subsequent calls to this method will overwrite the previous handler.
217+
*
218+
* @param callable(\Throwable|\Exception $error)|null $callback The callback to execute; null will clear the current handler.
219+
*
220+
* @return void
221+
*/
222+
public static function setErrorHandler(callable $callback = null)
223+
{
224+
self::get()->setErrorHandler($callback);
225+
}
226+
225227
/**
226228
* Check whether an optional feature is supported by the current event loop
227229
* driver.

src/LoopDriver.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,6 @@ public function onWritable($stream, callable $callback, $data = null);
8585
*/
8686
public function onSignal($signo, callable $callback, $data = null);
8787

88-
/**
89-
* Execute a callback when an error occurs.
90-
*
91-
* @param callable(\Throwable|\Exception $exception) $callback The callback to execute.
92-
*
93-
* @return string An identifier that can be used to cancel, enable or disable the watcher.
94-
*/
95-
public function onError(callable $callback);
96-
9788
/**
9889
* Enable a watcher.
9990
*
@@ -144,6 +135,17 @@ public function reference($watcherId);
144135
*/
145136
public function unreference($watcherId);
146137

138+
/**
139+
* Set a callback to be executed when an error occurs.
140+
*
141+
* Subsequent calls to this method will overwrite the previous handler.
142+
*
143+
* @param callable(\Throwable|\Exception $error)|null $callback The callback to execute; null will clear the current handler.
144+
*
145+
* @return void
146+
*/
147+
public function setErrorHandler(callable $callback = null);
148+
147149
/**
148150
* Check whether an optional features is supported by this implementation
149151
* and system.

0 commit comments

Comments
 (0)