Deamon class

A typed, isolate-local broadcast event bus with per-subscriber sticky replay.

Keep each StreamSubscription and cancel it when its owner leaves. Buses do not bridge isolates, browser tabs or platform processes; sticky cache keys use the emission generic type.

Gallery walkthrough · browser route /#/events. These examples use the current checkout; published 1.x APIs can differ.

Await one event

import 'package:activity/activity.dart';

Future<void> main() async {
  final bus = Deamon();
  try {
    final next = bus.next<String>(); // Subscribe before emitting.
    bus.emit('ready');
    assert(await next == 'ready');
  } finally {
    await bus.close();
  }
}

Replay the latest typed value

import 'package:activity/activity.dart';

Future<void> main() async {
  final bus = Deamon();
  try {
    bus.emitSticky<int>(3);
    assert(await bus.onSticky<int>().first == 3);
    bus.clearSticky<int>();
  } finally {
    await bus.close();
  }
}

Constructors

Deamon({bool sync = false})
Deamon.withController(StreamController<Object?> controller)

Properties

hashCode → int
The hash code for this object.
no setterinherited
hasListener → bool
Whether any listeners are attached.
no setter
isClosed → bool
Whether the stream is closed.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stream → Stream<Object?>
The stream of all events (raw).
no setter
streamController → StreamController<Object?>
no setter

Methods

clearSticky<T extends Object?>() → void
Clears sticky events of type T, or all if T is Object/dynamic.
close() → Future<void>
Closes the event bus.
destroy() → void
emit(Object? event) → void
Emits a new event.
emitError(Object error, [StackTrace? stackTrace]) → void
Emits an error event.
emitSticky<T extends Object?>(T event) → void
Emits a sticky event (cached by type).
listen<T extends Object?>(void onData(T), {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription<T>
Subscribes to events immediately.
next<T extends Object?>() → Future<T>
Returns the next event of type T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on<T extends Object?>() → Stream<T>
Subscribes to events of type T.
onSticky<T extends Object?>() → Stream<T>
Subscribes to sticky + future events of type T.
spawn(Object? event) → void
toString() → String
A string representation of this object.
inherited

Operators

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