LCOV - code coverage report

Current view
top level - src/local_worker - local_worker.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines111478.6%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2
3import 'package:logger/web.dart';
4import 'package:using/using.dart';
5
6import '../_impl/xplat/_local_worker.dart'
7 if (dart.library.io) '../_impl/native/_local_worker.dart'
8 if (dart.library.html) '../_impl/web/_local_worker.dart'
9 if (dart.library.js_interop) '../_impl/web/_local_worker.dart' as impl;
10import '../channel.dart';
11import '../exceptions/exception_manager.dart';
12import '../iworker.dart';
13import '../worker/worker_request.dart';
14import '../worker_service.dart';
15
16/// Base local worker class.
17///
18/// Local workers are similar to other Workers except that they run in the
19/// context of the current thread. They do not create any platform thread
20/// (such as Isolate or Web Worker) but they provide a [channel] that can be
21/// shared with other workers to support communication between threads. One
22/// interesting use-case is accessing UI components or platform plugins in
23/// Flutter, where only code running in the main thread is allowed access to
24/// such features. Creating a [LocalWorker] in the main application and sharing
25/// its [channel] with other workers enables providing access to Flutter
26/// features.
27///
28/// Local workers wrap around a [WorkerService]. Messages sent to the local
29/// worker are deserialized as [WorkerRequest]s and dispatched to a handler
30/// defined in the [_service]'s [WorkerService.operations] map according to the
31/// [WorkerRequest.command].
32abstract base class LocalWorker<W extends WorkerService>
33 with Releasable
34 implements WorkerService, IWorker {
351 LocalWorker(this._service);
36
372 factory LocalWorker.create(W service, [ExceptionManager? exceptionManager]) =>
382 impl.createLocalWorker<W>(
392 service, exceptionManager ?? ExceptionManager());
40
41 final W _service;
42
431 @override
441 void release() {
451 stop();
462 super.release();
471 }
48
49 @override
50 Logger? channelLogger;
51
520 @override
53 ExceptionManager get exceptionManager =>
540 (_exceptionManager ??= ExceptionManager());
55 ExceptionManager? _exceptionManager;
56
57 /// The local worker's [Channel].
58 Channel? get channel;
59
60 /// A [Channel] to communicate with this local worker. This channel should be
61 /// provided to clients so they can invoke services from the local worker.
620 Channel? get sharedChannel => channel?.share();
63
64 /// Starts the local worker.
65 @override
66 FutureOr<void> start();
67
68 /// Stops the local worker.
69 @override
70 void stop();
71
72 /// Forward to underlying service.
731 @override
743 Map<int, CommandHandler> get operations => _service.operations;
75}
Choose Features