Line data Source code
1 : import 'dart:io'; 2 : import 'dart:math'; 3 : 4 : import 'package:combine/src/combine_worker/combine_worker_manager.dart'; 5 : import 'package:combine/src/combine_worker/effective_worker_factory.dart'; 6 : import 'package:combine/src/combine_worker/native_worker_manager.dart'; 7 : import 'package:combine/src/combine_worker/worker_manager_factory/combine_worker_manager_factory.dart'; 8 : import 'package:combine/src/combine_worker_singleton.dart'; 9 : import 'package:flutter/foundation.dart'; 10 : 11 : class NativeWorkerManagerFactory implements CombineWorkerManagerFactory { 12 1 : @override 13 : CombineWorkerManager create({ 14 : int tasksPerIsolate = defaultTasksPerIsolate, 15 : int? isolatesCount, 16 : }) { 17 1 : return NativeWorkerManager( 18 : tasksPerIsolate: tasksPerIsolate, 19 1 : isolatesCount: isolatesCount ?? calculateIsolatesCount(), 20 : ); 21 : } 22 : 23 1 : @visibleForTesting 24 : int calculateIsolatesCount() { 25 1 : final isolatesCountForTest = testIsolatesCount; 26 : if (isolatesCountForTest != null) { 27 : return isolatesCountForTest; 28 : } else { 29 1 : final numberOfProcessors = Platform.numberOfProcessors; 30 2 : final isolatesCount = max(1, (numberOfProcessors / 2).floor()); 31 : return isolatesCount; 32 : } 33 : } 34 : } 35 : 36 : typedef CombineWorkerManagerFactoryImpl = NativeWorkerManagerFactory;