call method

Future<Response> call(
  1. Request req
)

Implementation

Future<Response> call(Request req) {
  // Recorded once, by whoever answers last. A server that tries the router
  // first and renders the page itself when the router has no route for it
  // records the status it sent, and the router's 404 on the way is not a
  // request of its own.
  if (Zone.current[_measuredOutside] == true) return _dispatch(req);
  final int start = _startMeasuring(req);
  if (start < 0) return measure(req, () => _dispatch(req));
  // What [measure] does for this case, without an async function around
  // the route's own: that was one more suspend state, future, frame copy
  // and resumption for every request. Recorded as the answer completes,
  // before whoever awaits it goes on.
  return _measuringZone()
      .runUnary<Future<Response>, Request>(_dispatchTearOff, req)
      .then((Response response) {
    _finishMeasuring(req, start, response: response);
    return response;
  }, onError: (Object error, StackTrace stack) {
    // The server turns this into a 500 inside a bare `catch (_)`, so if it
    // is not recorded here the exception is gone.
    _finishMeasuring(req, start, error: error, stackTrace: stack);
    Error.throwWithStackTrace(error, stack);
  });
}