Skip to main content

solo 0.3.0 copy "solo: ^0.3.0" to clipboard
solo: ^0.3.0 copied to clipboard

One job at a time: sequential jobs with exclusive state ownership, declarative rules and cooperative cancellation. Pure Dart.

example/example.md

solo example #

A fake camera controller: hardware that answers late and may break on its own, and a controller that keeps the state honest. It shows a sealed state hierarchy, working types, job keys and policies, cooperative cancellation and an observer that prints every job. Camera example builds this controller one decision at a time.

Run it from this directory:

dart pub get
dart run bin/main.dart

The output is one line per job and per state change, printed by the observer in bin/main.dart:

[init] started
state: Preparing()
state: Ready(zoom: 1.0, focusPoint: null, paused: false)
[init] finished Done(null)
[setZoom: zoom: 2.0] started
...
[takePhoto] finished Cancelled(manual)
[dispose] started
> [closeCamera] started
> [closeCamera] finished Done(null)
state: Disposed()
[dispose] finished Done(null)
shot: Cancelled(manual)
closed

The shot is cancelled on purpose: the program disposes of the camera while the shot is halfway through, and dispose cancels it before it closes the device.

The controller itself is in lib/src/camera_controller.dart, its state in lib/src/camera_state.dart, and the tests in test/camera_controller_test.dart show how to drive it with fake_async. Run them from this directory:

dart test
0
likes
0
points
1.01k
downloads

Publisher

verified publisheryet-another.dev

Weekly Downloads

One job at a time: sequential jobs with exclusive state ownership, declarative rules and cooperative cancellation. Pure Dart.

Repository (GitHub)
View/report issues

Topics

#state-management #async #cancellation #concurrency

License

unknown (license)

Dependencies

async_job, meta

More

Packages that depend on solo