functions.php

File

This file is part of fast-forward/defer.

Description

This source file is subject to the license bundled with this source code in the file LICENSE.

Tags
copyright

Description

Copyright (c) 2026 Felipe Sayão Lobato Abreu github@mentordosnerds.com

license

Description

https://opensource.org/licenses/MIT MIT License

Table of Contents

Functions

defer()

Creates a new Defer instance, optionally registering a callback immediately.

 : DeferInterface
using()

Executes a callback within a controlled scope, ensuring resources are released at the end.

 : mixed
scope()

Executes a callback within a deferred scope, ensuring all registered callbacks are executed at the end.

 : mixed
Functions

Functions

defer()

Creates a new Defer instance, optionally registering a callback immediately.

defer([ callable|null  $callback = null], mixed  ...$arguments) : DeferInterface

Description

This function MUST return a DeferInterface implementation. If a callback is provided, it SHALL be registered.

Parameters
$callback : callable|null = null

Description

the callback to register (optional)

$arguments : mixed

Description

Arguments for the callback.

Return values

Description

the Defer instance

using()

Executes a callback within a controlled scope, ensuring resources are released at the end.

using( callable  $factory, callable  $callback) : mixed

Description

This function MUST create a Defer instance, pass it to the factory, and execute the callback. The Defer instance SHALL be unset after execution.

Parameters
$factory : callable

Description

a function that receives the Defer and returns the resource

$callback : callable

Description

a function that receives the resource and executes the desired logic

Return values

Description

the return value of the callback

scope()

Executes a callback within a deferred scope, ensuring all registered callbacks are executed at the end.

scope( callable  $callback) : mixed

Description

This function MUST create a Defer instance, pass it to the callback, and unset it after execution.

Parameters
$callback : callable

Description

a function that receives the Defer and executes the desired logic

Return values

Description

the return value of the callback