send method

Future<MmWsReply> send(
  1. MmWsAction action
)

Implementation

Future<MmWsReply> send(MmWsAction action) async {
  if (_ws == null || _ws!.closeCode != null) await connect();

  var completer = Completer<MmWsReply>();
  var seq = _nextSeq++;
  var tosend = action.toJson();
  tosend['seq'] = seq;
  _actionCompleters[seq] = completer;
  _ws?.add(json.encode(tosend));
  return completer.future.timeout(Duration(seconds: 2), onTimeout: () {
    _actionCompleters.remove(seq);
    return MmWsReply.noReply();
  });
}