Prepares and sends HTTP requests.

@param callable $callback
557561
protected function makeRequest(callable $callback = null)
    {
        // Foreach request:
        foreach ($this->requests as $key => $request) {
            $data = (isset($this->data[$key]) and $this->data[$key] !== null) ? $this->data[$key] : null;

            // Follow any 3xx HTTP status code.
            $request->setOption(CURLOPT_FOLLOWLOCATION, true);

            switch ($this->verb) {
                case 'DELETE':
                    $this->prepareDeleteRequest($request);
                    break;
                case 'GET':
                    $this->prepareGetRequest($request);
                    break;
                case 'POST':
                    $this->preparePostRequest($request, $data);
                    break;
                case 'PUT':
                    $this->preparePutRequest($request, $data);
                    break;
            }

            // Add the request to the dispatcher.
            $this->dispatcher->add($request);
        }

        // Execute the request(s).
        if ($callback !== null) {
            $this->dispatcher->execute($callback);
        } else {
            $this->dispatcher->execute();
        }
    }
932977
public function progressFunction(callable $callback)
    {
        if (! is_callable($callback)) {
            throw new \InvalidArgumentException('Not is_callable progressFunction');
        }

        if (! $this->settings()->is('send_progress_in_http_headers')) {
            $this->settings()->set('send_progress_in_http_headers', 1);
        }
        if (! $this->settings()->is('http_headers_progress_interval_ms')) {
            $this->settings()->set('http_headers_progress_interval_ms', 100);
        }

        $this->transport()->setProgressFunction($callback);
    }
274879
public function onLogQuery(callable $callback = null)
    {
        if ($callback === null || is_callable($callback)) {
            $this->on_log_query = $callback;
        } else {
            throw new InvalidArgumentException('Callback needs to be NULL or callable');
        }
    }
791099
public function wrap_callback(callable $callback, array $args=[]) {
		ob_start();
		foreach (self::$override_args as $key => $val)
			$args[$key] = $val;
		$callback($args);
		self::$body_raw = ob_get_clean();
		self::$body = json_decode(self::$body_raw, true);
		if (self::$body) {
			self::$errno = self::$body['errno'];
			self::$data = self::$body['data'];
		} else {
			self::$errno = 0;
			self::$data = [];
		}
	}
158890
protected function wrapCallback(callable $callback)
    {
        return function ($response, $connection, $command) use ($callback) {
            if ($command && !$response instanceof ResponseInterface) {
                $response = $command->parseResponse($response);
            }

            \call_user_func($callback, $response, $this, $command);
        };
    }
785165
protected static function runCallback($callback, $args)
    {
        if (!is_array($args)) {
            $args = isset($args) ? array($args) : array();
        }
        return call_user_func_array($callback, $args);
    }
437233
public function set(string $name, callable $callback): void
    {
        $this->services[$name] = function ($c) use ($callback) {
            static $object;

            if ($object === null) {
                $object = $callback($c);
            }

            return $object;
        };
    }
422861
public function setEditableCallback($callback)
    {
        $this->isEditable() ?: $this->setEditable();
        $this->editableCallback = $callback;

        return $this;
    }
954172
public function setJsonCallbackWrap($callback)
    {

        if (empty($callback)) {
            $this->jsonCallbackWrap = false;
            return;
        }

        if (!is_string($callback)) {
            throw new \Exception('JSON callback wrap should be a string or false.');
        }

        $this->jsonCallbackWrap = $callback;
    }
1219251
public function map($callback)
    {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('Callback has to be a valid callable, '.gettype($callback).' given.');
        }

        for ($i = 0; $this->checkIfLineNumberIsValid($i, false); $i++) {
            $this->setCurrentLineNumber($i);
            call_user_func($callback, $this->getLine($i), $i, $this);
        }
    }
217257
public function preprocess(callable $callback)
    {
        if ($callback instanceof Closure) {
            $callback = $callback->bindTo($this, get_class($this));
        }

        $this->getPreprocessor()->register($callback);
        return $this;
    }
596594
public function send($callback)
    {
        $this->id = getInstance()->server->task($this->taskProxyData, -1, $callback);
        if ($this->id === false) {
            throw new Exception("worker->tasker send async task failed, data: " . dump($this->taskProxyData, false, true));
        }

        return $this;
    }
1193464
public function viaRequest( $name, callable $callback )
	{
		$this->guards[$name] = new RequestGuard( $callback, Request::i() );
	}
1255587
public function handleNotify(callable $callback)
    {
        $notify = $this->getNotify();

        if (!$notify->isValid()) {
            throw new FaultException('Invalid request payloads.', 400);
        }

        $notify = $notify->getNotify();
        $successful = $notify->get('result_code') === 'SUCCESS';

        $handleResult = call_user_func_array($callback, [$notify, $successful]);

        if (is_bool($handleResult) && $handleResult) {
            $response = [
                'return_code' => 'SUCCESS',
                'return_msg'  => 'OK',
            ];
        } else {
            $response = [
                'return_code' => 'FAIL',
                'return_msg'  => $handleResult,
            ];
        }

        return new Response(XML::build($response));
    }
295897
public static function error(callable $callback = null){
        $callback
          ? is_callable($callback) && static::$error = $callback
          : static::$error && call_user_func(static::$error);
    }
549479
public function resolve(callable $callback = null)
    {
        $active = null;
        $mh = $this->getMainHandle();

        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc === CURLM_CALL_MULTI_PERFORM);

        while ($active && $mrc === CURLM_OK) {
            if (curl_multi_select($mh) === -1) {
                usleep(100);
            }

            do {
                $mrc = curl_multi_exec($mh, $active);
            } while ($mrc === CURLM_CALL_MULTI_PERFORM);
        }

        if ($mrc !== CURLM_OK) {
            throw new \RuntimeException("Curl multi read error $mrc\n", E_USER_WARNING);
        }

        /** @var CurlTransport $transport */
        $responses = [];
        $errors = [];
        $transport = $this->getTransport();

        foreach ($this->tasks as $task) {
            /** @var Promise $promise */
            $handle = $task['handle'];
            $promise = $task['promise'];

            $error = curl_error($handle);

            if (!$error) {
                $responses[] = $res = $transport->getResponse(curl_multi_getcontent($handle), curl_getinfo($handle));
                $promise->resolve($res);
            } else {
                $errors[] = $e = new \RuntimeException($error, curl_errno($handle));
                $promise->reject($e);
            }
        }

        $this->errors = $errors;

        if ($callback) {
            $callback($responses, $errors, $this);
        }

        $this->reset();

        return $responses;
    }
92950
public function each(callable $callback = null)
	{
		foreach($this->list as $item)
		{
			if(call_user_func($callback, $item) === false)
				return $this;
		}
		
		return $this;
	}