singleResponseFuture<R> function

Future<R> singleResponseFuture<R>(
  1. void action(
    1. SendPort responsePort
    ),
  2. {@Deprecated("Use singleResponseFutureWithTimeout instead") Duration? timeout,
  3. @Deprecated("Use singleResponseFutureWithTimeout instead") R? timeoutValue}
)

Creates a Future, and a SendPort that can be used to complete that future.

Calls action with the response SendPort, then waits for someone to send a value on that port The returned Future is completed with the value sent on the port.

If action throws, which it shouldn't, the returned future is completed with that error. Any return value of action is ignored, and if it is asynchronous, it should handle its own errors.

If timeout is supplied, it is used as a limit on how long it can take before the message is received. If a message isn't received in time, the timeoutValue used as the returned future's value instead. If the result type, R, does not allow null, and timeout is provided, then timeoutValue must also be non-null. Use singleResponseFutureWithTimeout instead of providing the optional parameters to this function. It prevents getting run-time errors from providing a timeout and no timeoutValue with a non-nullable result type.

If you need a timeout on the operation, it's recommended to specify a timeout using singleResponseFutureWithTimeout, and not use Future.timeout on the returned Future. The Future method won't be able to close the underlying ReceivePort, and will keep waiting for the first response anyway.

Implementation

Future<R> singleResponseFuture<R>(
  void Function(SendPort responsePort) action, {
  @Deprecated("Use singleResponseFutureWithTimeout instead") Duration? timeout,
  @Deprecated("Use singleResponseFutureWithTimeout instead") R? timeoutValue,
}) {
  if (timeout == null) {
    return _singleResponseFuture<R>(action);
  }
  if (timeoutValue is! R) {
    throw ArgumentError.value(
        null, "timeoutValue", "The result type is non-null");
  }
  return singleResponseFutureWithTimeout(action, timeout, timeoutValue);
}