withBatch method

void withBatch (
  1. dynamic callback(

    Runs callback and batches any requests sent until it returns.

    A batch of requests is sent in a single message on the underlying stream, and the responses are likewise sent back in a single message.

    callback may be synchronous or asynchronous. If it returns a Future, requests will be batched until that Future returns; otherwise, requests will only be batched while synchronously executing callback.

    If this is called in the context of another withBatch call, it just invokes callback without creating another batch. This means that responses are batched until the first batch ends.


    void withBatch(Function() callback) {
      if (_batch != null) return callback();
      _batch = [];
      return tryFinally(callback, () {
        _batch = null;