LCOV - code coverage report

Current view
top level - src - channel.dart
Test
lcov.info
Date
2026-03-04
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines66100.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_message.dart';
16import 'worker/worker_request.dart';
17import 'worker/worker_response.dart';
18
19/// A [Channel] supports communication from a client to a platform worker. It
20/// is used to send a [WorkerRequest] to a platform worker.
21abstract interface class Channel {
22 /// The [ExceptionManager] attached to this channel.
23 ExceptionManager get exceptionManager;
24
25 /// The [Logger] attached to this channel.
26 Logger? get logger;
27
28 /// [Channel] serialization. Returns an opaque object that can be transfered
29 /// from the client to the worker.
30 PlatformChannel serialize();
31
32 /// [Channel] sharing. Returns a [Channel] object that can be provided to
33 /// enable another worker to call the channel's worker.
34 Channel share();
35
36 /// Returns a [Future] that will complete when the channel is closed. This is
37 /// the same [Future] as the one returned by [close].
38 Future<void> get closed;
39
40 /// Sends a termination [WorkerRequest] to the worker. The [Channel] should
41 /// release any resource related to the worker and should not be used after
42 /// this method has been called.
43 Future<void> close();
44
45 /// Sends a close stream [WorkerRequest] to the worker.
46 void cancelStream(StreamId streamId);
47
48 /// Sends a cancel token [WorkerRequest] to the worker.
49 void cancelToken(SquadronCancelationToken? token);
50
51 /// Creates a [WorkerRequest] and sends it to the worker. This method expects
52 /// a single value from the worker.
53 Future<dynamic> sendRequest(int command, List args,
54 {SquadronCancelationToken? token,
55 bool inspectRequest = false,
56 bool inspectResponse = false});
57
58 /// Creates a [WorkerRequest] and sends it to the worker. This method expects
59 /// a stream of values from the worker. The worker must send a
60 /// [WorkerResponse.closeStream] message to close the [Stream].
61 Stream<dynamic> sendStreamingRequest(int command, List args,
62 {SquadronCancelationToken? token,
63 bool inspectRequest = false,
64 bool inspectResponse = false});
65
66 /// Starts a worker using the [entryPoint] and sends a start [WorkerRequest]
67 /// with [startArguments]. The future must not complete before the worker is
68 /// ready to serve requests.
6911 static Future<Channel> open(
70 ExceptionManager exceptionManager,
71 Logger? logger,
72 EntryPoint entryPoint,
73 List startArguments,
74 PlatformThreadHook? hook,
75 ) =>
7611 impl.openChannel(
77 entryPoint, exceptionManager, logger, startArguments, hook);
78
79 /// Deserializes a [Channel] from an opaque [channelInfo].
803 static Channel? deserialize(
81 PlatformChannel? channelInfo, [
82 Logger? logger,
83 ExceptionManager? exceptionManager,
84 ]) =>
853 impl.deserialize(channelInfo, logger, exceptionManager);
86}
87
88@internal
89extension ChannelImpl on Channel {
904 void terminate(TaskTerminatedException ex) => impl.terminateChannel(this, ex);
91
9212 int getActiveConnections() => impl.getActiveConnections(this);
93}
Choose Features