isolate_compute.dart

DartMaster

Explorer

C40
C++40
C#40
Dart
Beginner10
Intermediate10
Advanced10
Expert5
Master5
stream_transformer.dart
isolate_compute.dart
mixin_state.dart
extension_async.dart
zone_error.dart
Go40
Java40
JavaScript40
Kotlin40
Objective-C40
Perl40
PHP40
Python40
R40
Ruby40
Rust40
Shell40
Swift40
TypeScript40
isolate_compute.dart
Click to focus
1
2
3
4
5
6
7
8
9
Future<R> compute<T, R>(R Function(T) fn, T input) async {
   final port = ReceivePort();
   await Isolate.spawn((msg) {
       final [SendPort p, T data] = msg as List;
       p.send(fn(data));
   }, [port.sendPort, input]);
   return await port.first as R;
}
final result = await compute(heavyTask, data);
0WPM0%0:000/307(0%)|Ln 1, Col 1
UTF-8Dart

Related Exercises