use<T> static method

Future<T> use<T>(
  1. Future<T> fn(
    1. Network
    )
)

Creates a network, runs fn with it, and removes the network afterwards.

The network is removed even if fn throws. This is the recommended way to use a Network in a test to ensure cleanup:

await Network.use((net) async {
  // attach containers and run test assertions
});

Implementation

static Future<T> use<T>(Future<T> Function(Network) fn) async {
  final network = Network();
  await network.create();
  try {
    return await fn(network);
  } finally {
    await network.remove();
  }
}