onReassemble static method

void onReassemble(
  1. FutureOr<void> callback()
)

Runs callback after every hot reload of this process, once the new code is in: where a server builds again what it built once from the old code — its router, its middleware, an app object holding both.

A hot reload gives every function and method its new code, but a closure made before it keeps its old body, and a router's handlers are closures made when it was built. So a route added never exists and a handler edited runs as it was, until something builds the router again: this. It is what ext.flutter.reassemble is to a Flutter app.

late App app;
await serve((request) => app.handler(request), 'localhost', 8080);
app = App(database);
FlutterwareServer.onReassemble(() {
  unawaited(app.dispose());
  app = App(database);
});

A world calls it after it reloads the server it hosts. Callbacks run in the order they were registered, each awaited; one that throws does not stop the next, and the reload reports it. Where nothing reloads the process — production — it never runs.

Implementation

static void onReassemble(FutureOr<void> Function() callback) =>
    _Reassembly.add(callback);