scope<S, R> static method

Future<R> scope<S, R>(
  1. Shard<S> shard,
  2. Future<R> body(
    1. ShardTester<S> tester
    )
)

Creates a ShardTester around shard, runs body, and disposes the tester in a finally block. Returns whatever body returns.

Type parameter S is the shard's state type (named S to avoid shadowing the outer class's T in this static method).

Implementation

static Future<R> scope<S, R>(
  Shard<S> shard,
  Future<R> Function(ShardTester<S> tester) body,
) async {
  final tester = ShardTester<S>(shard);
  try {
    return await body(tester);
  } finally {
    await tester.dispose();
  }
}