@@ -70,27 +70,26 @@ export class Session {
70
70
71
71
/**
72
72
* Send a command or a message to the peer.
73
+ * If the session is not running, the promise will be rejected with {@link Error}.
73
74
* @param data The data to send.
74
- * @throws If the session is not running.
75
75
*/
76
76
send ( data : Command | Message ) : Promise < void > {
77
77
if ( ! this . #running) {
78
- throw new Error ( "Session is not running" ) ;
78
+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
79
79
}
80
80
const { innerWriter } = this . #running;
81
81
return innerWriter . write ( data ) ;
82
82
}
83
83
84
84
/**
85
85
* Receive a message from the peer.
86
+ * If the session is not running or the message ID is already reserved, the promise will be rejected with {@link Error}.
86
87
* @param msgid The message ID to receive.
87
88
* @returns The received message.
88
- * @throws If the session is not running.
89
- * @throws If the message ID is already reserved.
90
89
*/
91
90
recv ( msgid : number ) : Promise < Message > {
92
91
if ( ! this . #running) {
93
- throw new Error ( "Session is not running" ) ;
92
+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
94
93
}
95
94
const { reservator } = this . #running;
96
95
return reservator . reserve ( msgid ) ;
@@ -157,25 +156,25 @@ export class Session {
157
156
158
157
/**
159
158
* Wait until the session is shutdown.
159
+ * If the session is not running, the promise will be rejected with {@link Error}.
160
160
* @returns A promise that is fulfilled when the session is shutdown.
161
- * @throws If the session is not running.
162
161
*/
163
162
wait ( ) : Promise < void > {
164
163
if ( ! this . #running) {
165
- throw new Error ( "Session is not running" ) ;
164
+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
166
165
}
167
166
const { waiter } = this . #running;
168
167
return waiter ;
169
168
}
170
169
171
170
/**
172
171
* Shutdown the session.
172
+ * If the session is not running, the promise will be rejected with {@link Error}.
173
173
* @returns A promise that is fulfilled when the session is shutdown.
174
- * @throws If the session is not running.
175
174
*/
176
175
shutdown ( ) : Promise < void > {
177
176
if ( ! this . #running) {
178
- throw new Error ( "Session is not running" ) ;
177
+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
179
178
}
180
179
// Abort consumer to shutdown session properly.
181
180
const { consumerController, waiter } = this . #running;
@@ -185,12 +184,12 @@ export class Session {
185
184
186
185
/**
187
186
* Shutdown the session forcibly.
187
+ * If the session is not running, the promise will be rejected with {@link Error}.
188
188
* @returns A promise that is fulfilled when the session is shutdown.
189
- * @throws If the session is not running.
190
189
*/
191
190
forceShutdown ( ) : Promise < void > {
192
191
if ( ! this . #running) {
193
- throw new Error ( "Session is not running" ) ;
192
+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
194
193
}
195
194
// Abort consumer and producer to shutdown session forcibly.
196
195
const { consumerController, producerController, waiter } = this . #running;
0 commit comments