Skip to content

Releases: thesis-php/sync-once

0.2.0 PHP 8.4, drop $isAlive

Choose a tag to compare

@vudaltsov vudaltsov released this 09 Jul 01:41

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 any callable, not just a \Closure.
  • The minimum PHP version is now 8.4.

0.1.3 Free function from memory if $isAlive is null

Choose a tag to compare

@vudaltsov vudaltsov released this 21 Nov 20:44
15df6d9

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

Choose a tag to compare

@vudaltsov vudaltsov released this 21 Nov 19:26

What's Changed

Full Changelog: 0.1.1...0.1.2

0.1.1 Rename $factory to $function

Choose a tag to compare

@vudaltsov vudaltsov released this 07 May 18:31

Changed

  • Rename Once::$factory to Once::$function.

0.1.0 Initial release

Choose a tag to compare

@vudaltsov vudaltsov released this 07 May 18:23
Improve README.md