LCOV - code coverage report

Current view
top level - src - channel.dart
Test
lcov.info
Date
2025-11-15
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_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 /// Returns a [Future] that will complete when the channel is closed. This is
36 /// the same [Future] as the one returned by [close].
37 Future<void> get closed;
38
39 /// Sends a termination [WorkerRequest] to the worker. The [Channel] should
40 /// release any resource related to the worker and should not be used after
41 /// this method has been called.
42 FutureOr<void> close();
43
44 /// Sends a close stream [WorkerRequest] to the worker.
45 FutureOr<void> cancelStream(int streamId);
46
47 /// Sends a cancel token [WorkerRequest] to the worker.
48 FutureOr<void> cancelToken(SquadronCancelationToken? token);
49
50 /// Creates a [WorkerRequest] and sends it to the worker. This method expects
51 /// a single value from the worker.
52 Future<dynamic> sendRequest(int command, List args,
53 {SquadronCancelationToken? token,
54 bool inspectRequest = false,
55 bool inspectResponse = false});
56
57 /// Creates a [WorkerRequest] and sends it to the worker. This method expects
58 /// a stream of values from the worker. The worker must send a
59 /// [WorkerResponse.closeStream] message to close the [Stream].
60 Stream<dynamic> sendStreamingRequest(int command, List args,
61 {SquadronCancelationToken? token,
62 bool inspectRequest = false,
63 bool inspectResponse = false});
64
65 /// Starts a worker using the [entryPoint] and sends a start [WorkerRequest]
66 /// with [startArguments]. The future must not complete before the worker is
67 /// ready to serve requests.
6811 static Future<Channel> open(
69 ExceptionManager exceptionManager,
70 Logger? logger,
71 EntryPoint entryPoint,
72 List startArguments,
73 PlatformThreadHook? hook,
74 ) =>
7511 impl.openChannel(
76 entryPoint, exceptionManager, logger, startArguments, hook);
77
78 /// Deserializes a [Channel] from an opaque [channelInfo].
793 static Channel? deserialize(
80 PlatformChannel? channelInfo, [
81 Logger? logger,
82 ExceptionManager? exceptionManager,
83 ]) =>
843 impl.deserialize(channelInfo, logger, exceptionManager);
85}
86
87@internal
88extension ChannelImpl on Channel {
894 void terminate(TaskTerminatedException ex) => impl.terminateChannel(this, ex);
90
9112 int get activeConnections => impl.getActiveConnections(this);
92}
Choose Features