Skip to content

Commit c6d19a0

Browse files
Update example app
1 parent 789608b commit c6d19a0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

example/lib/main.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class _DemoPageState extends State<DemoPage> {
3838
Task.simultaneousA: Status.stopped,
3939
Task.simultaneousB: Status.stopped,
4040
Task.simultaneousC: Status.stopped,
41-
Task.compute: Status.stopped,
41+
Task.isolate: Status.stopped,
4242
};
4343
CancellationToken? _cancellationToken;
4444

@@ -75,15 +75,14 @@ class _DemoPageState extends State<DemoPage> {
7575
setState(() => _tasks[Task.simultaneousC] = Status.complete)),
7676
]);
7777

78-
// To run a function in a cancellable isolate, use cancellableCompute in
79-
// place of the Flutter's compute function
80-
setState(() => _tasks[Task.compute] = Status.running);
81-
await cancellableCompute(
82-
delayedIsolateFunction,
83-
const Duration(seconds: 2),
78+
// To run a function in a cancellable isolate, use CancellableIsolate.run
79+
// or cancellableCompute
80+
setState(() => _tasks[Task.isolate] = Status.running);
81+
await CancellableIsolate.run(
82+
() => delayedIsolateFunction(const Duration(seconds: 2)),
8483
_cancellationToken,
8584
);
86-
setState(() => _tasks[Task.compute] = Status.complete);
85+
setState(() => _tasks[Task.isolate] = Status.complete);
8786
} on CancelledException {
8887
// In some cases, like when cancelling tasks because in a widget's
8988
// dispose method, you'll want to catch the CancellationException but
@@ -140,8 +139,8 @@ class _DemoPageState extends State<DemoPage> {
140139
status: _tasks[Task.simultaneousC]!,
141140
),
142141
TaskStatusDisplay(
143-
label: 'Compute status',
144-
status: _tasks[Task.compute]!,
142+
label: 'Isolate status',
143+
status: _tasks[Task.isolate]!,
145144
),
146145
const SizedBox(height: 16.0),
147146
ElevatedButton(
@@ -170,8 +169,7 @@ Future<void> delayedFuture() async {
170169
/// A simple function for testing isolates.
171170
///
172171
/// If you cancel running tasks whilst this isolate is sleeping, the isolate
173-
/// will be killed and you'll only see the 'Isolate started' message in the
174-
/// console.
172+
/// will be killed and you'll only see the 'Isolate started' message in the log.
175173
void delayedIsolateFunction(Duration delay) {
176174
if (kDebugMode) print('Isolate started - Waiting ${delay.inSeconds} seconds');
177175
sleep(delay);

example/lib/types/task.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ enum Task {
33
simultaneousA,
44
simultaneousB,
55
simultaneousC,
6-
compute,
6+
isolate,
77
}

0 commit comments

Comments
 (0)