September 2019
Beginner
512 pages
12h 52m
English
As said before, to create an isolate to perform long processes, we use the compute() function. We can have any kind of implementation in the isolate callback, which will be passed to the compute function. The only requirement is that it has to be a top-level function. For example, see the following code:
import 'dart:io';void backgroundCompute(args) { print('background compute callback'); print('calculating fibonacci from a background process'); int first = 0; int second = 1; for (var i = 2; i <= 50; i++) { var temp = second; second = first + second; first = temp; sleep(Duration(milliseconds: 200)); print("first: $first, second: $second."); } print('finished calculating fibo');}
This method calculates the first 50 Fibonacci ...
Read now
Unlock full access