nexus-runtime
Runtime abstractions and async primitives shared by all Nexus packages: the Runtime interface, Duration, mailbox contracts, Future/FutureSlot, and Cancellable.
What's in this package
Monadial\Nexus\Runtime\Runtime\
Runtime— interface implemented byFiberRuntime,SwooleRuntime, andStepRuntimeCancellable—cancel()+isCancelled()handle for scheduled tasks
Monadial\Nexus\Runtime\
Duration— immutable nanosecond-precision value object; factory methodsseconds,millis,micros,nanos,zero; arithmeticplus,minus,multipliedBy,dividedBy; conversiontoNanos,toMillis,toSecondsFloat
Monadial\Nexus\Runtime\Async\
Future<T>— read-side async result handle;await(),map(),flatMap(),isResolved(),cancel()FutureSlot<T>— write-side resolver;resolve(),fail(),cancel(),onCancel()
Monadial\Nexus\Runtime\Mailbox\
Mailbox<T>—enqueue,dequeue,dequeueBlocking,count,isFull,isEmpty,closeMailboxConfig—bounded(capacity, strategy),unbounded()OverflowStrategyenum —DropNewest,DropOldest,Backpressure,ThrowExceptionEnqueueResultenum —Accepted,Dropped,Backpressured
Monadial\Nexus\Runtime\Exception\
MailboxClosedException,MailboxOverflowException,MailboxTimeoutException,FutureTimeoutException
Install
composer require nexus-actors/runtime
Quick example
src/Runtime/DurationExample.php
use Monadial\Nexus\Runtime\Duration;
$timeout = Duration::seconds(5)->plus(Duration::millis(500));
echo $timeout->toMillis(); // 5500
echo $timeout->toSecondsFloat(); // 5.5
echo $timeout; // "5s 500ms"
$budget = Duration::seconds(10)->dividedBy(2);
echo $budget->isGreaterThan(Duration::seconds(4)); // true
See also
- nexus-runtime-fiber —
FiberRuntimeimplementation - nexus-runtime-swoole —
SwooleRuntimeimplementation - nexus-runtime-step —
StepRuntimefor deterministic tests