ports library

Utility functions for setting up ports and sending data.

This library contains a number of functions that handle the boiler-plate of setting up a receive port and receiving a single message on the port.

There are different functions that offer different ways to handle the incoming message.

The simplest function, singleCallbackPort, takes a callback and returns a port, and then calls the callback for the first message sent on the port.

Other functions intercept the returned value and either does something with it, or puts it into a Future or Completer.

Classes

SingleResponseChannel<R>
A Future and a SendPort that can be used to complete the future.

Functions

completeFutureResult<R>(List<Object?> response, Completer<R> completer) → void
Completes a completer with a message created by sendFutureResult
receiveFutureResult<R>(List<Object?> response) Future<R>
Converts a received message created by sendFutureResult to a future result.
sendFutureResult(Future<Object?> future, SendPort resultPort) → void
Send the result of a future, either value or error, as a message.
singleCallbackPort<P>(void callback(P response), {Duration? timeout, P? timeoutValue}) SendPort
Create a SendPort that accepts only one message.
singleCallbackPortWithTimeout<P>(void callback(P response), Duration timeout, P timeoutValue) SendPort
Create a SendPort that accepts only one message.
singleCompletePort<R, P>(Completer<R> completer, {FutureOr<R> callback(P message)?, Duration? timeout, FutureOr<R> onTimeout()?}) SendPort
Create a SendPort that accepts only one message.
singleResponseFuture<R>(void action(SendPort responsePort), {Duration? timeout, R? timeoutValue}) Future<R>
Creates a Future, and a SendPort that can be used to complete that future.
singleResponseFutureWithTimeout<R>(void action(SendPort responsePort), Duration timeout, R timeoutValue) Future<R>
Same as singleResponseFuture, but with required timeoutValue, this allows us not to require a nullable return value
singleResultFuture<R>(void action(SendPort responsePort), {Duration? timeout, FutureOr<R> onTimeout()?}) Future<R>
Creates a Future, and a SendPort that can be used to complete that future.