worker_bee library

Multi-platform workers for Dart (Web, VM).

Classes

AsyncCache<T>
Runs asynchronous functions and caches the result for a period of time.
AsyncMemoizer<T>
A class for running an asynchronous function exactly once and caching its result.
AWSLogger
A logging utility providing the ability to emit log entries, configure the level at which entries are emitted, and register plugins which can handle log entries as they're emitted.
AWSLoggerPlugin
A plugin to an AWSLogger which handles log entries emitted at the LogLevel of the logger instance.
CancelableCompleter<T>
A completer for a CancelableOperation.
CancelableOperation<T>
An asynchronous operation that can be cancelled.
ChunkedStreamReader<T>
Utility class for reading elements from a chunked stream.
DelegatingEventSink<T>
Simple delegating wrapper around an EventSink.
DelegatingFuture<T>
A wrapper that forwards calls to a Future.
DelegatingSink<T>
Simple delegating wrapper around a Sink.
DelegatingStream<T>
Simple delegating wrapper around a Stream.
DelegatingStreamChannel<T>
A simple delegating wrapper around StreamChannel.
DelegatingStreamConsumer<T>
Simple delegating wrapper around a StreamConsumer.
DelegatingStreamSink<T>
Simple delegating wrapper around a StreamSink.
DelegatingStreamSubscription<T>
Simple delegating wrapper around a StreamSubscription.
Disconnector<T>
Allows the caller to force a channel to disconnect.
ErrorResult
A result representing a thrown error.
EventSinkBase<T>
An abstract class that implements EventSink in terms of onAdd, onError, and onClose methods.
FutureGroup<T>
A collection of futures waits until all added Futures complete.
IOSinkBase
An abstract class that implements dart:io's IOSink's API in terms of onAdd, onError, onClose, and onFlush methods.
IsolateChannel<T>
A StreamChannel that communicates over a ReceivePort/SendPort pair, presumably with another isolate.
LazyStream<T>
A Stream wrapper that forwards to another Stream that's initialized lazily.
LogEntry
A discrete log event emitted by an AWSLogger.
MultiChannel<T>
A class that multiplexes multiple virtual channels across a single underlying transport layer.
NullStreamSink<T>
A StreamSink that discards all events.
RestartableTimer
A non-periodic timer that can be restarted any number of times.
Result<T>
The result of a computation.
ResultFuture<T>
A Future wrapper that provides synchronous access to the result of the wrapped Future once it's completed.
SendPorts
Ports passed to a VM worker bee for relaying messages and exits.
SingleSubscriptionTransformer<S, T>
A transformer that converts a broadcast stream into a single-subscription stream.
StreamChannel<T>
An abstract class representing a two-way communication channel.
StreamChannelCompleter<T>
A channel where the source and destination are provided later.
StreamChannelController<T>
A controller for exposing a new StreamChannel.
StreamChannelMixin<T>
A mixin that implements the instance methods of StreamChannel in terms of stream and sink.
StreamChannelTransformer<S, T>
A StreamChannelTransformer transforms the events being passed to and emitted by a StreamChannel.
StreamCloser<T>
A StreamTransformer that allows the caller to forcibly close the transformed Stream.
StreamCompleter<T>
A single-subscription stream where the contents are provided later.
StreamGroup<T>
A collection of streams whose events are unified and sent through a central stream.
StreamQueue<T>
An asynchronous pull-based interface for accessing stream events.
StreamQueueTransaction<T>
A transaction on a StreamQueue, created by StreamQueue.startTransaction.
StreamSinkBase<T>
An abstract class that implements StreamSink in terms of onAdd, onError, and onClose methods.
StreamSinkCompleter<T>
A sink where the destination is provided later.
StreamSinkTransformer<S, T>
A StreamSinkTransformer transforms the events being passed to a sink.
StreamSplitter<T>
A class that splits a single source stream into an arbitrary number of (single-subscription) streams (called "branch") that emit the same events.
StreamZip<T>
A stream that combines the values of other streams.
SubscriptionStream<T>
A Stream adapter for a StreamSubscription.
ValueResult<T>
A result representing a returned value.
VirtualChannel<T>
A virtual channel created by MultiChannel.
WorkerAssignment
The worker bee assignment sent from the main thread.
WorkerBee
Annotation class for marking worker bees.
WorkerBeeBase<Request extends Object, Response>
The base class for all worker bees.
WorkerHive
Annotation class for the main method which marks your workers' entrypoint, i.e. the method you call runHive from.
WorkerLogEntry
A LogEntry emitted by a worker bee.

Enums

LogLevel
The different levels of logging.

Extensions

AsyncExpand on Stream<T>
Alternatives to asyncExpand.
AsyncMap on Stream<T>
Alternatives to asyncMap.
CastStreamSink on StreamSink<I>
Helper for casting StreamSinks.
ChunkedStreamReaderByteStreamExt on ChunkedStreamReader<int>
Extensions for using ChunkedStreamReader with byte-streams.
CombineLatest on Stream<T>
Utilities to combine events from multiple streams through a callback or into a list.
Concatenate on Stream<T>
Utilities to append or prepend to a stream.
Merge on Stream<T>
Utilities to interleave events from multiple streams.
RateLimit on Stream<T>
Utilities to rate limit events.
Scan on Stream<T>
A utility similar to fold which emits intermediate accumulations.
StreamExtensions on Stream<T>
Utility extensions on Stream.
StreamSinkExtensions on StreamSink<T>
Extensions on StreamSink to make stream transformations more fluent.
Switch on Stream<T>
A utility to take events from the most recent sub stream returned by a callback.
SwitchLatest on Stream<Stream<T>>
A utility to take events from the most recent sub stream.
TakeUntil on Stream<T>
A utility to end a stream based on an external trigger.
Tap on Stream<T>
A utility to chain extra behavior on a stream.
Where on Stream<T>
Utilities to filter events.
WhereNotNull on Stream<T?>

Properties

currentUri Uri
The current URI of the running worker.
no setter
isWebWorker bool
Whether the current script is running inside a web worker.
no setter
jsonDocument StreamChannelTransformer<Object?, String>
A StreamChannelTransformer that transforms JSON documents—strings that contain individual objects encoded as JSON—into decoded Dart objects.
final

Functions

collectBytes(Stream<List<int>> source) Future<Uint8List>
Collects an asynchronous sequence of byte lists into a single list of bytes.
collectBytesCancelable(Stream<List<int>> source) CancelableOperation<Uint8List>
Collects an asynchronous sequence of byte lists into a single list of bytes.
getWorkerAssignment() Future<WorkerAssignment>
Awaits assignment from the main process.
runHive(Map<String, WorkerBeeBuilder<WorkerBeeBase<Object, dynamic>>> workers, [FutureOr<void> runApp()?]) Future<void>
Initializes worker bees by checking if running in a web worker, and awaiting the assigned role if so.
subscriptionTransformer<T>({Future handleCancel(StreamSubscription<T>)?, void handlePause(StreamSubscription<T>)?, void handleResume(StreamSubscription<T>)?}) StreamTransformer<T, T>
Creates a StreamTransformer that modifies the behavior of subscriptions to a stream.
typedStreamTransformer<S, T>(StreamTransformer transformer) StreamTransformer<S, T>
Creates a wrapper that coerces the type of transformer.

Typedefs

VmEntrypoint = Future<void> Function(SendPorts)
The function signature for the generated VM entrypoint, as required by Isolate.spawn.
WorkerBeeBuilder<W extends WorkerBeeBase<Object, dynamic>> = W Function()
Factory for a worker bee.

Exceptions / Errors

WorkerBeeException
An error encountered in a worker bee, serializable using built_value.