LCOV - code coverage report

Current view
top level - src - channel.dart
Test
lcov.info
Date
2025-03-26
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines55100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2
3import 'package:logger/web.dart';
4import 'package:meta/meta.dart';
5
6import '_impl/xplat/_channel.dart'
7 if (dart.library.io) '_impl/native/_channel.dart'
8 if (dart.library.html) '_impl/web/_channel.dart'
9 if (dart.library.js) '_impl/web/_channel.dart'
10 if (dart.library.js_interop) '_impl/web/_channel.dart' as impl;
11import 'exceptions/exception_manager.dart';
12import 'exceptions/task_terminated_exception.dart';
13import 'tokens/_squadron_cancelation_token.dart';
14import 'typedefs.dart';
15import 'worker/worker_request.dart';
16import 'worker/worker_response.dart';
17
18/// A [Channel] supports communication from a client to a platform worker. It
19/// is used to send a [WorkerRequest] to a platform worker.
20abstract interface class Channel {
21 /// The [ExceptionManager] attached to this channel.
22 ExceptionManager get exceptionManager;
23
24 /// The [Logger] attached to this channel.
25 Logger? get logger;
26
27 /// [Channel] serialization. Returns an opaque object that can be transfered
28 /// from the client to the worker.
29 PlatformChannel serialize();
30
31 /// [Channel] sharing. Returns a [Channel] object that can be provided to
32 /// enable another worker to call the channel's worker.
33 Channel share();
34
35 /// Sends a termination [WorkerRequest] to the worker. The [Channel] should
36 /// release any resource related to the worker and should not be used after
37 /// this method has been called.
38 FutureOr<void> close();
39
40 /// Sends a close stream [WorkerRequest] to the worker.
41 FutureOr<void> cancelStream(int streamId);
42
43 /// Sends a cancel token [WorkerRequest] to the worker.
44 FutureOr<void> cancelToken(SquadronCancelationToken? token);
45
46 /// Creates a [WorkerRequest] and sends it to the worker. This method expects
47 /// a single value from the worker.
48 Future<dynamic> sendRequest(int command, List args,
49 {SquadronCancelationToken? token,
50 bool inspectRequest = false,
51 bool inspectResponse = false});
52
53 /// Creates a [WorkerRequest] and sends it to the worker. This method expects
54 /// a stream of values from the worker. The worker must send a
55 /// [WorkerResponse.closeStream] message to close the [Stream].
56 Stream<dynamic> sendStreamingRequest(int command, List args,
57 {SquadronCancelationToken? token,
58 bool inspectRequest = false,
59 bool inspectResponse = false});
60
61 /// Starts a worker using the [entryPoint] and sends a start [WorkerRequest]
62 /// with [startArguments]. The future must not complete before the worker is
63 /// ready to serve requests.
6411 static Future<Channel> open(
65 ExceptionManager exceptionManager,
66 Logger? logger,
67 EntryPoint entryPoint,
68 List startArguments,
69 PlatformThreadHook? hook,
70 ) =>
7111 impl.openChannel(
72 entryPoint, exceptionManager, logger, startArguments, hook);
73
74 /// Deserializes a [Channel] from an opaque [channelInfo].
753 static Channel? deserialize(
76 PlatformChannel? channelInfo, [
77 Logger? logger,
78 ExceptionManager? exceptionManager,
79 ]) =>
803 impl.deserialize(channelInfo, logger, exceptionManager);
81}
82
83@internal
84extension ChannelTerminationImpl on Channel {
852 void terminate(TaskTerminatedException ex) => impl.terminateChannel(this, ex);
86}
Choose Features