close method

void close()

Close this Notify and fail all current and future waiters.

All currently waiting tasks will fail with StateError, and any future calls to notified will return a failed future.

// ignore_for_file: unused_element

import 'package:cross_channel/notify.dart';

Future<void> main() async {
  final shutdownNotify = Notify();

  // Force shutdown after grace period
  Future<void> forceShutdown() async {
    await Future<void>.delayed(Duration(seconds: 30)); // Grace period
    shutdownNotify.close(); // Force all remaining waiters to fail
  }
}

Implementation

void close() {
  if (_closed) return;
  _closed = true;
  while (_waiters.isNotEmpty) {
    final c = _waiters.removeLast();
    if (!c.isCompleted) {
      c.completeError(StateError('Notify.disconnected'));
    }
  }
}