Releases: thesis-php/sync-once
Release list
0.2.0 PHP 8.4, drop $isAlive
A complete rewrite of Once. The function now runs eagerly, its result — value or exception — is memoized permanently, and the function itself is released from memory as soon as it completes.
This release contains breaking changes. See the migration notes below.
Breaking changes
$isAlive is gone
Once::__construct() no longer accepts a second parameter. A memoized value can no longer be invalidated and recalculated:
// Before
$once = new Once($function, static fn(Connection $c) => $c->isAlive());
// After — no equivalent. Recreate the Once, or use a dedicated cache.
$once = new Once($function);The function is invoked eagerly
Previously the function ran lazily, on the first await() call. It now starts in the constructor, which means side effects begin at construction time and constructing a Once requires a running event loop.
Exceptions are memoized
An exception thrown by the function is now stored and rethrown on every await(). Previously the function was reexecuted on the next call, which made a Once that failed silently retry.
Cancellation no longer discards the running function
Passing a Cancellation to await() aborts only that particular await. The function keeps running and its result stays memoized for other awaiters.
LogicException on a freed function is gone
await() no longer throws LogicException('Function has been freed from memory'). The function is released automatically once it completes.
Other changes
Once::__construct()accepts anycallable, not just a\Closure.- The minimum PHP version is now 8.4.
0.1.3 Free function from memory if $isAlive is null
What's Changed
- Free function from memory if $isAlive is null by @vudaltsov in #2
Full Changelog: 0.1.2...0.1.3
0.1.2 Support `null` values
0.1.1 Rename $factory to $function
Changed
- Rename
Once::$factorytoOnce::$function.