使用回调来使用池子中的资源，无需手动释放
回调有两个参数：$resource(资源对象), $instance(操作实例对象，如数据库、Redis等)
本方法返回值为回调的返回值
@param string $name
@param callable $callback
@return mixed
558692
public static function use(string $name, callable $callback)
    {
        $resource = static::getResource($name);
        $result = null;
        try{
            $result = call_user_func($callback, $resource, $resource->getInstance());
        }
        finally{
            static::releaseResource($resource);
        }
        return $result;
    }
1142576
public function run($name, $callback) {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException('$callback is not callable');
        }

        // Because, we need to remove exists Instance before fork
        $this->Storage->setup();

        $pid = pcntl_fork();
        if ($pid === -1) {
            return false;
        }
        if ($pid) {
            // main fork
            $this->pids[$name] = $pid;
            return true;
        } else {
            $result = call_user_func($callback);
            $this->Storage->set($this->getKey(), $name, $result);
            exit(0);
        }
    }
971347
private function withOptionReference($name, $callback)
    {
        if (!$this->options) {
            $this->options = new ArrayObject();
        }

        return $this->withVariableReference($this->options, $name, $callback);
    }
415629
public function add(string $name, callable $callback): \IvoPetkov\BearFrameworkAddons\ServerRequests
    {
        $this->callbacks[$name] = $callback;
        return $this;
    }
631205
final public function map(Callable $callback)
	{
		$arr = array_map(
			$callback,
			array_values($this->{self::MAGIC_PROPERTY}),
			array_keys($this->{self::MAGIC_PROPERTY})
		);
		return static::createFromArray($arr);
	}
940022
public function bind(string $name, callable $callback): self
    {
        $this->data->bind($name, $callback);
        return $this;
    }
1290914
public function group($name, \Closure $callback)
    {
        $this->currentGroup = $name;

        $callback($this);

        $this->currentGroup = null;

        return $this;
    }
264525
public function singleton(string $name, callable $callback = null)
    {
        static $instance = [];

        // if closure callback given we will create a singleton instance of class
        // and return it to user
        if ($callback instanceof Closure) {
            if (!isset($instance[$name])) {
                $instance[$name] = $callback($this);
            }

            return $this->stack[$name] = $instance[$name];
        }

        /*
         | If callback is not instance of closure then we will simply
         | create a singleton instance and return it
         */
        if (!isset($instance[$name])) {
            $instance[$name] = new $name();
        }

        return $instance[$name];
    }
937584
public function extract(callable $callback = null)
    {

        if ($callback === null) {
            $result = $this->result->serialize();
        }
        else {
            $result = $callback($this->result->serialize());
        }

        return $result;

    }
1120858
public function execute($callback)
    {
        if (!$this->isBatch) {
            throw new \RuntimeException('Please batch json rpc first.');
        }
        $methods = $this->methods;
        $proxy = function ($err, $res) use ($methods, $callback) {
            if ($err !== null) {
                return call_user_func($callback, $err, null);
            }
            foreach ($methods as $key => $method) {
                if (isset($res[$key])) {
                    if (!is_array($res[$key])) {
                        $transformed = $method->transform([$res[$key]], $method->outputFormatters);
                        $res[$key] = $transformed[0];
                    } else {
                        $transformed = $method->transform($res[$key], $method->outputFormatters);
                        $res[$key] = $transformed;
                    }
                }
            }
            return call_user_func($callback, null, $res);
        };
        $this->requestManager->sendPayload('[' . implode(',', $this->batch) . ']', $proxy);
        $this->methods[] = [];
        $this->batch = [];
    }
1370825
protected function createResource(callable $callback)
    {
        $parameters = $this->parameters;
        $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT;

        if ($parameters->scheme === 'unix') {
            $uri = "unix://$parameters->path";
        } else {
            $uri = "$parameters->scheme://$parameters->host:$parameters->port";
        }

        if (!$stream = @stream_socket_client($uri, $errno, $errstr, 0, $flags)) {
            $this->onError(new ConnectionException($this, \trim($errstr), $errno));

            return;
        }

        \stream_set_blocking($stream, 0);

        $this->state->setState(State::CONNECTING);

        $this->loop->addWriteStream($stream, function ($stream) use ($callback) {
            if ($this->onConnect()) {
                \call_user_func($callback, $this);
                $this->write();
            }
        });

        $this->timeout = $this->armTimeoutMonitor(
            $parameters->timeout ?: 5, $this->errorCallback ?: function () { }
        );

        return $stream;
    }
762522
public function register($name, Closure $callback)
    {
        $this->checkCallbackName($name);

        $this->callbacks[$name] = $callback;

        return $this;
    }
477491
public static function createCallback(string $name, callable $callback): NormalizationFieldMappingBuilderInterface
    {
        $self = new self($name);
        $self->fieldNormalizer = new CallbackFieldNormalizer($callback);

        return $self;
    }
1347719
public function send($name = '', callable $callback)
    {
        $configs = Config::get($name);
        $driver = $this->driver(isset($configs['driver']) ? $configs['driver']: 'swift', $configs);

        return $callback($driver);
    }
87861
public static function make(callable $callback = null)
    {
        if (is_callable($callback) && !is_null($callback)) {
            return $callback(new static(new ApcWrapper()));
        }

        return new static(new ApcWrapper());
    }
1210719
public function item($name, Closure $callback = null)
    {
        if ($this->items->has($name)) {
            $item = $this->items->get($name);
        } else {
            $item = $this->container->make('Maatwebsite\Sidebar\Item');
            $item->name($name);
        }

        $this->call($callback, $item);

        $this->addItem($item);

        return $item;
    }
554547
public function make($name, $callback)
    {
        if (!is_callable($callback)) {
            return null;
        }

        if (!array_key_exists($name, $this->menu)) {
            $this->menu[$name] = new Builder($name, $this->loadConf($name));
        }

        // Registering the items
        call_user_func($callback, $this->menu[$name]);

        // Storing each menu instance in the collection
        $this->collection->put($name, $this->menu[$name]);

        // Make the instance available in all views
        View::share($name, $this->menu[$name]);

        return $this->menu[$name];
    }