FakeRequestHandler typedef

FakeRequestHandler = FutureOr<MagicResponse> Function(MagicRequest request)

Callback signature for dynamic request handling.

FutureOr rather than a bare MagicResponse so a stub may answer asynchronously. A synchronous stub is still the common case and still compiles unchanged; what the Future admits is a test that needs a request to stay OUTSTANDING while it does something else, which is the only way to script a concurrency case ("a sign-out arrives while the handshake is still in the air"). A stub that must answer before it returns cannot open that window at all.

Implementation

typedef FakeRequestHandler =
    FutureOr<MagicResponse> Function(MagicRequest request);