TrafficRecorderRun extension

The record-and-replay choreography for call/return sources, owned once.

A source whose request is one call that returns one result — a database statement, a cache lookup, a platform channel — has exactly one correct way to use TrafficRecorder: describe lazily, ask TrafficRecorder.decide, serve a replay, throw a rejection, or run the live call and then record its result. run is that choreography, so an adapter supplies only the description, the live call, and (optionally) how a recorded response decodes back to its native type:

Future<List<Row>> query(String sql) => recorder.run(
      describe: () => RecordedRequest(
        source: 'sqlite', operation: 'query', target: sql),
      live: () => database.query(sql),
      decode: Row.fromRecorded,
    );

Transports that split request and response stages (Dio's interceptor chain) render the decision by hand instead — see RecorderInterceptor.

on

Methods

run<T>({required RecordedRequest describe(), required Future<T> live(), T decode(Object? recorded)?, ReplayMissBehavior onMiss = ReplayMissBehavior.forward, Object reject(String message) = StateError.new}) Future<T>

Available on TrafficRecorder, provided by the TrafficRecorderRun extension

Serves one call/return request through the recorder.