File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,14 @@ export class Notify {
3535 /**
3636 * Notifies `n` waiters that are waiting for notification. Resolves each of the notified waiters.
3737 * If there are fewer than `n` waiters, all waiters are notified.
38+ *
39+ * @param n The number of waiters to notify.
40+ * @throws {RangeError } if `n` is not a positive safe integer.
3841 */
3942 notify ( n = 1 ) : void {
43+ if ( n <= 0 || ! Number . isSafeInteger ( n ) ) {
44+ throw new RangeError ( `n must be a positive safe integer, got ${ n } ` ) ;
45+ }
4046 const it = iter ( this . #waiters) ;
4147 for ( const waiter of take ( it , n ) ) {
4248 waiter . resolve ( ) ;
Original file line number Diff line number Diff line change 11import { delay } from "@std/async/delay" ;
2- import { assertEquals , assertRejects } from "@std/assert" ;
2+ import { assertEquals , assertRejects , assertThrows } from "@std/assert" ;
33import { promiseState } from "./promise_state.ts" ;
44import { Notify } from "./notify.ts" ;
55
@@ -109,4 +109,17 @@ Deno.test("Notify", async (t) => {
109109 ) ;
110110 } ,
111111 ) ;
112+
113+ await t . step (
114+ "'notify' throws RangeError if size is not a positive safe integer" ,
115+ ( ) => {
116+ const notify = new Notify ( ) ;
117+ assertThrows ( ( ) => notify . notify ( NaN ) , RangeError ) ;
118+ assertThrows ( ( ) => notify . notify ( Infinity ) , RangeError ) ;
119+ assertThrows ( ( ) => notify . notify ( - Infinity ) , RangeError ) ;
120+ assertThrows ( ( ) => notify . notify ( - 1 ) , RangeError ) ;
121+ assertThrows ( ( ) => notify . notify ( 1.1 ) , RangeError ) ;
122+ assertThrows ( ( ) => notify . notify ( 0 ) , RangeError ) ;
123+ } ,
124+ ) ;
112125} ) ;
You can’t perform that action at this time.
0 commit comments