@@ -486,3 +486,49 @@ it("variable.define allows other variables to begin computation before a generat
486
486
assert . strictEqual ( await gen . _promise , 3 , "gen cell 3" ) ;
487
487
assert . strictEqual ( await val . _promise , 3 , "val cell 3" ) ;
488
488
} ) ;
489
+
490
+ it ( "variable.define does not report stale fulfillments" , async ( ) => {
491
+ const runtime = new Runtime ( ) ;
492
+ const module = runtime . module ( ) ;
493
+ const values = [ ] ;
494
+ const errors = [ ] ;
495
+ const variable = module . variable ( {
496
+ fulfilled ( value ) {
497
+ values . push ( value ) ;
498
+ } ,
499
+ rejected ( error ) {
500
+ errors . push ( error ) ;
501
+ }
502
+ } ) ;
503
+ const promise = new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( "value1" ) , 250 ) ) ;
504
+ variable . define ( ( ) => promise ) ;
505
+ await runtime . _computing ;
506
+ variable . define ( ( ) => "value2" ) ;
507
+ await promise ;
508
+ assert . deepStrictEqual ( await valueof ( variable ) , { value : "value2" } ) ;
509
+ assert . deepStrictEqual ( values , [ "value2" ] ) ;
510
+ assert . deepStrictEqual ( errors , [ ] ) ;
511
+ } ) ;
512
+
513
+ it ( "variable.define does not report stale rejections" , async ( ) => {
514
+ const runtime = new Runtime ( ) ;
515
+ const module = runtime . module ( ) ;
516
+ const values = [ ] ;
517
+ const errors = [ ] ;
518
+ const variable = module . variable ( {
519
+ fulfilled ( value ) {
520
+ values . push ( value ) ;
521
+ } ,
522
+ rejected ( error ) {
523
+ errors . push ( error ) ;
524
+ }
525
+ } ) ;
526
+ const promise = new Promise ( ( resolve , reject ) => setTimeout ( ( ) => reject ( "error1" ) , 250 ) ) ;
527
+ variable . define ( ( ) => promise ) ;
528
+ await runtime . _computing ;
529
+ variable . define ( ( ) => Promise . reject ( "error2" ) ) ;
530
+ await promise . catch ( ( ) => { } ) ;
531
+ assert . deepStrictEqual ( await valueof ( variable ) , { error : "error2" } ) ;
532
+ assert . deepStrictEqual ( values , [ ] ) ;
533
+ assert . deepStrictEqual ( errors , [ "error2" ] ) ;
534
+ } ) ;
0 commit comments