send method

Future<Object?> send(
  1. SendPort to,
  2. List<Object?> message
)

Sends message to to and gives the answer.

Implementation

Future<Object?> send(SendPort to, List<Object?> message) {
  ReceivePort replies = _replies ??= ReceivePort()..listen(_onReply);
  int id = _nextId++;
  _Call call = _Call(_nowMs() + timeout.inMilliseconds);
  _waiting[id] = call;
  // ponytail: a request can fail up to timeout / 5 late, fine for a
  // safety net that is not on the normal path
  _timer ??= Timer.periodic(timeout ~/ 5, _check);
  try {
    to.send(<Object?>[replies.sendPort, id, ...message]);
  } catch (_) {
    _waiting.remove(id);
    if (_waiting.isEmpty) _stopTimer();
    rethrow;
  }
  return call.done.future;
}