Get your
own
website
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
import 'dart:async'; import 'dart:isolate'; int countPrimes(int max) { int count = 0; for (int n = 2; n <= max; n++) { bool isPrime = true; for (int d = 2; d * d <= n; d++) { if (n % d == 0) { isPrime = false; break; } } if (isPrime) count++; } return count; } Future
main() async { int ticks = 0; final timer = Timer.periodic(Duration(milliseconds: 100), (t) { ticks++; }); int primes = await Isolate.run(() => countPrimes(5000000)); timer.cancel(); print('Primes up to 5 million: $primes'); print('Did the timer run? ${ticks > 0}'); }
Primes up to 5 million: 348513
Did the timer run? true