PHPDaemon\Core\CallbackWrapper::wrap PHP Method

wrap() public static method

Wraps callback
public static wrap ( callable $cb, double $timeout = null, $ctx = false ) : Closure
$cb callable
$timeout double = null
return Closure
    public static function wrap($cb, $timeout = null, $ctx = false)
    {
        if ($cb instanceof CallbackWrapper || Daemon::$context === null && $timeout === null) {
            return $cb;
        }
        if ($cb === null) {
            return null;
        }
        return new static($cb, $timeout, $ctx !== false ? $ctx : Daemon::$context);
    }

Usage Example

Example #1
0
 public function status($phone, $id, $cb, $all = 0)
 {
     $cb = CallbackWrapper::wrap($cb);
     $this->appInstance->httpclient->get(['http://smsc.ru/sys/status.php', 'login' => $this->config->login->value, 'psw' => $this->config->password->value, 'phone' => $phone, 'id' => $id, 'fmt' => 3, 'all' => $all], function ($conn, $success) use($cb) {
         call_user_func($cb, json_decode($conn->body, true));
     });
 }
All Usage Examples Of PHPDaemon\Core\CallbackWrapper::wrap