Line data Source code
1 : import 'package:combine/src/combine_isolate/combine_isolate.dart'; 2 : import 'package:combine/src/isolate_factory/effective_isolate_factory.dart'; 3 : import 'package:combine/src/isolate_factory/isolate_factory.dart'; 4 : 5 : /// [Combine] is used to [spawn] a new [CombineIsolate]. 6 : class Combine { 7 5 : factory Combine() { 8 5 : return _instance; 9 : } 10 : 11 5 : Combine._(); 12 : 13 : /// `late` is used to make this singleton lazy. So it will be initialized 14 : /// only while first usage. 15 15 : static late final _instance = Combine._(); 16 : 17 : /// Create a new [CombineIsolate] which is just a representation of `Isolate` 18 : /// so when you create a [CombineIsolate]. 19 : /// 20 : /// `Isolate` will be created under the hood except web platform. 21 : /// 22 : /// [entryPoint] is a function which will be called in Isolate. 23 5 : Future<CombineIsolate> spawn<T>( 24 : IsolateEntryPoint<T> entryPoint, { 25 : T? argument, 26 : bool errorsAreFatal = true, 27 : String? debugName = "combine_isolate", 28 : }) async { 29 10 : return effectiveIsolateFactory.create( 30 : entryPoint, 31 : argument: argument, 32 : debugName: debugName, 33 : errorsAreFatal: errorsAreFatal, 34 : ); 35 : } 36 : }