| 1 | | | import '../pool/worker_pool.dart'; |
| 2 | | | import '../worker/worker.dart'; |
| 3 | | | import 'target_platform.dart'; |
| 4 | | | |
| 5 | | | const localService = SquadronService.local(); |
| 6 | | | const vmService = SquadronService.vm(); |
| 7 | | | const sharedService = SharedServiceParam._(); |
| 8 | | | |
| 9 | | | @Deprecated('Use sharedService instead.') |
| 10 | | | const localWorker = SharedServiceParam._(); |
| 11 | | | |
| 12 | | | class SharedServiceParam { |
| 13 | | 12 | const SharedServiceParam._(); |
| 14 | | | } |
| 15 | | | |
| 16 | | | /// Annotation for service classes to be wrapped as workers. |
| 17 | | | class SquadronService { |
| 18 | | 12 | const SquadronService({ |
| 19 | | | this.pool = true, |
| 20 | | | this.targetPlatform = TargetPlatform.all, |
| 21 | | | String? baseUrl, |
| 22 | | | this.version, |
| 23 | | | }) : baseUrl = baseUrl ?? '', |
| 24 | | | local = false; |
| 25 | | | |
| 26 | | 1 | const SquadronService.web({bool pool = true, String? baseUrl, int? version}) |
| 27 | | 1 | : this( |
| 28 | | | pool: pool, |
| 29 | | | targetPlatform: TargetPlatform.web, |
| 30 | | | baseUrl: baseUrl, |
| 31 | | | version: version, |
| 32 | | | ); |
| 33 | | | |
| 34 | | 12 | const SquadronService.vm({bool pool = true}) |
| 35 | | 12 | : this(pool: pool, targetPlatform: TargetPlatform.vm); |
| 36 | | | |
| 37 | | 12 | const SquadronService.local() |
| 38 | | | : pool = false, |
| 39 | | | local = true, |
| 40 | | | targetPlatform = TargetPlatform.none, |
| 41 | | | baseUrl = '', |
| 42 | | | version = null; |
| 43 | | | |
| 44 | | | /// Controls code generation of a [WorkerPool] exposing the target service |
| 45 | | | /// class. `true` by default. |
| 46 | | | final bool pool; |
| 47 | | | |
| 48 | | | /// Controls code generation of [Worker] and [WorkerPool]. When `true`, no |
| 49 | | | /// [Worker] and no [WorkerPool] will be generated but instances of the service |
| 50 | | | /// class can be shared with other workers. |
| 51 | | | final bool local; |
| 52 | | | |
| 53 | | | /// Controls code generation of a entry points for various platforms. |
| 54 | | | final int targetPlatform; |
| 55 | | | |
| 56 | | | /// For Web-based workers, indicates the [baseUrl] where the Web Worker will |
| 57 | | | /// be exposed in production. |
| 58 | | | final String baseUrl; |
| 59 | | | |
| 60 | | | /// For Web-based workers, indicates the Worker's [version]. When provided, this |
| 61 | | | /// number will be included in the worker's URL as a query parameter. |
| 62 | | | final int? version; |
| 63 | | | } |