Transactional

@param callable $callback
@return int
490030
public function transactional($callback)
    {
        $n = 0;
        $em = $this->doctrine->getManager();
        $em->getConnection()->beginTransaction();
        $callback($n);
        $em->getConnection()->commit();
        return $n;
    }
1220321
public function consume(callable $callback) : int
    {
        $event = $this->getTimerEvent(__METHOD__);

        $count = $this->storage->consume($this->name, $callback);

        $event->addData([
            'count' => $count,
        ]);

        self::emit($event);

        return $count;
    }
111403
public function average(callable $callback = null)
    {

        if ($callback ===  null) {

            $average = parent::average(function ($time)
            {
                return $time->getSeconds();
            });

            return $this->createTime(0, 0, $average);
        }

        return parent::average($callback);
    }
1069129
public function transaction( Closure $callback )
	{
		$this->beginTransaction();

		// We'll simply execute the given callback within a try / catch block
		// and if we catch any exception we can rollback the transaction
		// so that none of the changes are persisted to the database.
		try
		{
			$result = $callback( $this );

			$this->commit();
		}

			// If we catch an exception, we will roll back so nothing gets messed
			// up in the database. Then we'll re-throw the exception so it can
			// be handled how the developer sees fit for their applications.
		catch ( Exception $e )
		{
			$this->rollBack();

			throw $e;
		}
		catch ( Throwable $e )
		{
			$this->rollBack();

			throw $e;
		}

		return $result;
	}
1278182
public function average($callback = null)
    {
        if ($count = $this->count()) {
            return $this->sum($callback) / $count;
        }
    }
798431
public function withTransaction(callable $callable)
    {
        try {
            $nested = $this->transactionStarted;
            if (!$nested) {
                $this->startTransaction();
            }
            $this->transactionStarted = true;
            $result = $callable();
            if (!$nested) {
                $this->commit();
            }
            $this->transactionStarted = $nested;
            return $result;
        } catch (Throwable $e) {
            if ($this->transactionStarted) {
                $this->rollback();
                $this->transactionStarted = false;
            }
            throw $e;
        }
    }
1191613
public function transaction(callable $callback, $that = null, $default = null)
    {
        if ($that === null) {
            $that = $this;
        }

        $pdo = $this->getPDO();

        if ($pdo->inTransaction()) {
            return $callback($that);
        }

        $result = $default;

        try {
            $pdo->beginTransaction();
            $result = $callback($that);
            $pdo->commit();
        } catch (PDOException $exception) {
            $pdo->rollBack();
            if ($this->throwTransactionExceptions) {
                throw $exception;
            }
        }

        return $result;
    }
934987
public function assertEquals(callable $callback): bool
    {
        $id = $this->getId($callback);

        return $this->id === $id;
    }
902347
public function unique(callable $callback) {
		$that = $this
				->group($callback)
				->map(function($group) {
					return $group[0];
				});
		return $that->resetKeys();
	}
328468
public function each(callable $callback)
	{
		foreach ($this->members as $key => $member)
		{
			if ($callback($key, $member) === false) {
				break;
			}
		}
		return $this;
	}
98525
public function sort(callable $callback = null)
    {
        $items = $this->items;

        $callback = $callback ?: function ($a, $b) {
            return $a == $b ? 0 : (($a < $b) ? -1 : 1);

        };

        uasort($items, $callback);

        return new static($items);
    }
1144985
protected function getRequiredType(callable $callback)
	{
		$ref = new \ReflectionFunction($callback);
		
		if($ref->getNumberOfParameters() > 0)
		{
			$params = $ref->getParameters();
			
			if(isset($params[0]) &&  NULL !== ($type = $params[0]->getClass()))
			{
				return $type;
			}
		}
	}
132033
public function transaction( \Closure $callback, $attempts = 1 )
	{
		$this->beginTransaction();
		try {
			$data = $callback();
			$this->commit();

			return $data;
		} catch ( \Exception $e ) {
			$this->rollBack();
			throw $e;
		}
	}
86744
protected function checkAndReturnCallable($callback)
    {
        if (is_string($callback)) {
            return function ($app) use ($callback) {
                return $app($callback);
            };
        }

        if (!is_callable($callback)) {
            $type = is_object($callback) ? get_class($callback) : gettype($callback);
            throw new InvalidArgumentException("Passed argument of type $type is not callable");
        }

        return $callback;
    }
25029
public function withBulkProcessing(callable $callback)
    {
        $bulkProcessing = $this->bulkProcessing;
        $this->bulkProcessing = true;
        try {
            /** @noinspection PhpUndefinedMethodInspection */
            $callback->__invoke();
        } catch (\Exception $exception) {
            $this->bulkProcessing = $bulkProcessing;
            throw $exception;
        }
        $this->bulkProcessing = $bulkProcessing;
    }
48133
public function setCallback($callback = null)
    {
        if (!is_null($callback) && !is_callable($callback)) {
            throw new Exception("callback must be of type callable or null");
        }

        $this->callback = $callback;

        return $this;
    }
1287937
public function tryFlatTransaction(callable $callback)
    {
        $autoStartTransaction = $this->inTransaction() === false;

        // If we're starting a transaction, we don't need to catch here
        if ($autoStartTransaction) {
            $this->beginTransaction();
        }
        try {
            /**
            * @var string|int|bool|float|null|array|object|resource $out
            */
            $out = $callback($this);
            // If we started the transaction, we should commit here
            if ($autoStartTransaction) {
                $this->commit();
            }

            return $out;
        } catch (Throwable $e) {
            // If we started the transaction, we should cleanup here
            if ($autoStartTransaction) {
                $this->rollBack();
            }

            throw $e;
        }
    }