singleCallbackPort<P> function
- void callback(
- P response
- @Deprecated("Use singleCallbackPortWithTimeout instead") Duration? timeout,
- @Deprecated("Use singleCallbackPortWithTimeout instead") P? timeoutValue,
Create a SendPort that accepts only one message.
The callback function is called once, with the first message
received by the receive port.
All further messages are ignored and the port is closed.
If timeout is supplied, it is used as a limit on how
long it can take before the message is received.
If a message has not been received within the timeout duration,
the callback is called with the timeoutValue instead, and
the port is closed.
If the message type, P, does not allow null and timeout is
non-null, then timeoutValue must be provided and non-null.
Use singleCallbackPortWithTimeout instead of the deprecated
members. That will prevent run-time error arising from calling
this method with a non-nullable P type and a null timeoutValue.
If the received value is not a P, it will cause an uncaught
asynchronous error in the current zone.
Returns the SendPort expecting the single message.
Equivalent to:
(new ReceivePort()
..first.timeout(duration, () => timeoutValue).then(callback))
.sendPort
when timeout is provided.
Implementation
SendPort singleCallbackPort<P>(void Function(P response) callback,
{@Deprecated("Use singleCallbackPortWithTimeout instead") Duration? timeout,
@Deprecated("Use singleCallbackPortWithTimeout instead") P? timeoutValue}) {
if (timeout == null) {
return _singleCallbackPort<P>(callback);
}
if (timeoutValue is! P) {
throw ArgumentError.value(
null, "timeoutValue", "The result type is non-null");
}
return singleCallbackPortWithTimeout<P>(callback, timeout, timeoutValue);
}