DisposableLayer class abstract interface

A Layer that owns something and needs telling when the server stops.

A rate limiter holding a client, a metrics layer with a flusher, an auth layer caching keys on a timer: each acquires a resource when it is built and has nowhere to release it, because Layer declares only Layer.toMiddleware. axum needs no equivalent — Rust drops a layer when its router goes — so this is Dart's problem rather than a borrowed shape.

close(drain:) disposes every one it finds on the router, inside the same budget it gives requests and background work.

It is a separate interface because Dart's implements requires every member to be re-declared, so adding a method to Layer — even one with a body — would break every existing layer.

final class RateLimit implements DisposableLayer {
  RateLimit(this._client);

  final RedisClient _client;

  @override
  Middleware toMiddleware() => ...;

  @override
  Future<void> dispose() => _client.close();
}
Implemented types

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → Future<void>
Releases whatever this layer acquired.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMiddleware() → Middleware
Builds the shelf middleware this value configures.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited