Skip to content

Instantly share code, notes, and snippets.

@dickermoshe
Created September 25, 2025 04:45
Show Gist options
  • Select an option

  • Save dickermoshe/a5f887d57918a9c2fdef3a5f8002a055 to your computer and use it in GitHub Desktop.

Select an option

Save dickermoshe/a5f887d57918a9c2fdef3a5f8002a055 to your computer and use it in GitHub Desktop.
import 'package:signals/signals.dart';
void main() async {
final number = signal(2);
final squared = computedAsync(() async {
print("Squaring ${number.value}...");
await Future.delayed(Duration(seconds: 1));
final result = number.value * number.value;
print("Squared ${number.value} to $result");
return result;
}, dependencies: [number]);
final cubed = computedAsync(() async {
final m = await squared.future;
print("Cubing ${m}...");
await Future.delayed(Duration(seconds: 1));
final result = m * m * m;
print("Cubed ${m} to $result");
return result;
}, dependencies: [squared]);
effect(() {
print("Current State: " + (cubed.value.value?.toString() ?? "null"));
});
while (true) {
await Future.delayed(Duration(seconds: 50));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment