@@ -70,27 +70,26 @@ export class Session {
7070
7171 /**
7272 * Send a command or a message to the peer.
73+ * If the session is not running, the promise will be rejected with {@link Error}.
7374 * @param data The data to send.
74- * @throws If the session is not running.
7575 */
7676 send ( data : Command | Message ) : Promise < void > {
7777 if ( ! this . #running) {
78- throw new Error ( "Session is not running" ) ;
78+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
7979 }
8080 const { innerWriter } = this . #running;
8181 return innerWriter . write ( data ) ;
8282 }
8383
8484 /**
8585 * 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}.
8687 * @param msgid The message ID to receive.
8788 * @returns The received message.
88- * @throws If the session is not running.
89- * @throws If the message ID is already reserved.
9089 */
9190 recv ( msgid : number ) : Promise < Message > {
9291 if ( ! this . #running) {
93- throw new Error ( "Session is not running" ) ;
92+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
9493 }
9594 const { reservator } = this . #running;
9695 return reservator . reserve ( msgid ) ;
@@ -157,25 +156,25 @@ export class Session {
157156
158157 /**
159158 * Wait until the session is shutdown.
159+ * If the session is not running, the promise will be rejected with {@link Error}.
160160 * @returns A promise that is fulfilled when the session is shutdown.
161- * @throws If the session is not running.
162161 */
163162 wait ( ) : Promise < void > {
164163 if ( ! this . #running) {
165- throw new Error ( "Session is not running" ) ;
164+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
166165 }
167166 const { waiter } = this . #running;
168167 return waiter ;
169168 }
170169
171170 /**
172171 * Shutdown the session.
172+ * If the session is not running, the promise will be rejected with {@link Error}.
173173 * @returns A promise that is fulfilled when the session is shutdown.
174- * @throws If the session is not running.
175174 */
176175 shutdown ( ) : Promise < void > {
177176 if ( ! this . #running) {
178- throw new Error ( "Session is not running" ) ;
177+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
179178 }
180179 // Abort consumer to shutdown session properly.
181180 const { consumerController, waiter } = this . #running;
@@ -185,12 +184,12 @@ export class Session {
185184
186185 /**
187186 * Shutdown the session forcibly.
187+ * If the session is not running, the promise will be rejected with {@link Error}.
188188 * @returns A promise that is fulfilled when the session is shutdown.
189- * @throws If the session is not running.
190189 */
191190 forceShutdown ( ) : Promise < void > {
192191 if ( ! this . #running) {
193- throw new Error ( "Session is not running" ) ;
192+ return Promise . reject ( new Error ( "Session is not running" ) ) ;
194193 }
195194 // Abort consumer and producer to shutdown session forcibly.
196195 const { consumerController, producerController, waiter } = this . #running;
0 commit comments