Create a coroutine

@param callable $cb

@return bool
547199
public static function create(callable $cb)
    {
        $tid = self::tid();
        return SwCoroutine::create(function () use ($cb, $tid) {
            $id = SwCoroutine::getuid();
            self::$idMap[$id] = $tid;

            PhpHelper::call($cb);
        });
    }
468203
protected function acquire($cb)
    {
        $this->appInstance->getkey('error:' . $this->sessId, function ($redis) use ($cb) {
            if (!$redis) {
                $this->internalServerError();
                return;
            }
            if ($redis->result !== null) {
                $this->error((int)$redis->result);
                return;
            }
            if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 0) {
                $this->anotherConnectionStillOpen();
                return;
            }
            $this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
                if (!$redis) {
                    $this->internalServerError();
                    return;
                }
                if ($redis->result > 0) {
                    $this->anotherConnectionStillOpen();
                    return;
                }
                $this->appInstance->subscribe('w8in:' . $this->sessId, [$this, 'w8in'], function ($redis) use ($cb) {
                    if (!$redis) {
                        $this->internalServerError();
                        return;
                    }
                    if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
                        $this->anotherConnectionStillOpen();
                        return;
                    }
                    $this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
                        if (!$redis) {
                            $this->internalServerError();
                            return;
                        }
                        if ($redis->result > 1) {
                            $this->anotherConnectionStillOpen();
                            return;
                        }
                        if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
                            $this->anotherConnectionStillOpen();
                            return;
                        }
                        $cb === null || $cb();
                    });
                });
            });
        });
    }
1022671
public function setInterval(callable $cb, float $timeout): array
    {
        $keepGoing = true;
        $f = null;

        $f = function () use ($cb, &$f, $timeout, &$keepGoing) {
            if ($keepGoing) {
                $cb();
                $this->setTimeout($f, $timeout);
            }
        };
        $this->setTimeout($f, $timeout);

        // Really the only thing that matters is returning the $keepGoing
        // boolean value.
        //
        // We need to pack it in an array to allow returning by reference.
        // Because I'm worried people will be confused by using a boolean as a
        // sort of identifier, I added an extra string.
        return ['I\'m an implementation detail', &$keepGoing];
    }
220937
def Asyncme(func, n=None, interval=0, default_callback=None, loop=None):
    """"""
    return coros(n, interval, default_callback, loop)(func)
1182472
public function map($cb)
    {
        $data = $this->storage;

        $new = [];

        foreach ($data as $key => $value) {
            $new[$key] = call_user_func_array($cb, [$value, $key]);
        }

        return new Collection($new);
    }
74102
public function map(callable $cb)
    {
        $count = count($this);
        $sfa = new SplFixedArray($count);
        for ($i = 0; $i < $count; $i++) {
            $sfa[$i] = $cb($this->sfa[$i], $i, $this);
        }
        return new static($sfa);
    }
746756
public function sort(callable $cb = null)
    {
        if ($cb) {
            // Custom searches can be easier on memory, but run absurdly slow
            // pre PHP7
            if (PHP_MAJOR_VERSION < 7) {
                return $this->arraySort($cb);
            }
            return $this->mergeSort($cb);
        }
        return $this->arraySort();
    }
286850
public function command($cmd, $q = '', $cb = null)
    {
        if ($this->state !== self::STATE_AUTH_OK) {
            return false;
        }

        $this->sendPacket($cmd, $q);

        $this->onResponse->push($cb);
        $this->checkFree();

        return true;
    }
644488
protected function sessionStartNew($cb = null)
    {
        FileSystem::tempnam(session_save_path(), $this->sessionPrefix, function ($fp) use ($cb) {
            if (!$fp) {
                $cb(false);
                return;
            }

            $this->sessionFp = $fp;
            $this->sessionId = substr(basename($fp->path), mb_orig_strlen($this->sessionPrefix));
            $this->setcookie(
                ini_get('session.name'),
                $this->sessionId,
                ini_get('session.cookie_lifetime'),
                ini_get('session.cookie_path'),
                ini_get('session.cookie_domain'),
                ini_get('session.cookie_secure'),
                ini_get('session.cookie_httponly')
            );

            $cb(true);
        });
    }
1132583
public function onResponse($cb)
    {
        if ($cb === null && !$this->noSAF) {
            return;
        }
        $this->onResponse->push($cb);
        $this->checkFree();
    }
1136659
public static function syncfs($cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!self::$supported) {
            if ($cb) {
                $cb(false);
            }
            return false;
        }
        return eio_syncfs($pri, $cb);
    }
596404
protected function initWorker($func, $cb = null) {
        try {
            $worker = new \GearmanWorker();
            $worker->setId($this->func . '@' . posix_getpid());
            $worker->setTimeout($this->timeout ? $this->timeout * 1000 : 5000);
            // Add Gearman Job Servers to Worker
            if (strpos($this->host, ',') > 0) {
                $connected = $worker->addServers($this->host);
            } else {
                $connected = $worker->addServer($this->host, $this->port);
            }
            if ($connected) {
                if (is_array($func)) {
                    foreach ($func as $f) {
                        $worker->addFunction($f[0], $f[1]);
                    }
                } else if (is_callable($cb)) {
                    $worker->addFunction($func, $cb);
                } else {
                    unset($worker);

                    return null;
                }

                return $worker;
            } else {
                log_error('Cannot connect to Gearmand Server: ' . $worker->error(), 'gearman.err');
            }
        } catch (\Exception $exception) {
            log_error($exception->getMessage(), 'gearman.err');
        }

        return null;
    }
1356176
public function each(callable $cb)
    {
        foreach ($this->storage as $key => $value) {
            call_user_func_array($cb, [$value, $key]);
        }
    }
245649
public function addEvent($id, callable $cb)
    {
        if (!isset($this->events[$id])) {
            $this->events[$id] = [];
        }

        $this->events[$id][] = $cb;
    }
965553
public static function createChild(\Closure $callback)
    {
        $puid = Context::getcoroutine();
        return \Swoole\Coroutine::create(function () use ($puid,$callback){
            Context::markParent($puid);
            \Swoole\Coroutine::call_user_func($callback);
        });
    }
586873
public static function call($cb, array $args = [])
    {
        if (!$cb) {
            return true;
        }

        if (\is_array($cb)) {
            [$obj, $mhd] = $cb;

            return \is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
        }

        if (\is_string($cb)) {
            if (\function_exists($cb)) {
                return $cb(...$args);
            }

            // a class name
            if (\class_exists($cb)) {
                $cb = new $cb;
            }
        }

        // a \Closure or Object implement '__invoke'
        if (\is_object($cb) && \method_exists($cb, '__invoke')) {
            return $cb(...$args);
        }

        throw new \InvalidArgumentException('the callback handler is not callable!');
    }
114607
function createSession(config, cb) {
  cb = utils.callOnce(cb)

  DEBUG("create", utils.JS(config))

  var channel = channels.createChannel(config.url)
  var session = new Session(channel, config, cb)
}