File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Runtime } from "@observablehq/runtime" ;
2+ import assert from "assert" ;
3+ import { sleep } from "../variable/valueof.js" ;
4+
5+ describe ( "runtime.dispose" , ( ) => {
6+ it ( "invalidates all variables" , async ( ) => {
7+ const runtime = new Runtime ( ) ;
8+ const main = runtime . module ( ) ;
9+ const log = [ ] ;
10+ main . variable ( true ) . define ( [ "invalidation" ] , async ( invalidation ) => {
11+ await invalidation ;
12+ log . push ( "invalidation" ) ;
13+ } ) ;
14+ await sleep ( ) ;
15+ runtime . dispose ( ) ;
16+ await sleep ( ) ;
17+ assert . deepStrictEqual ( log , [ "invalidation" ] ) ;
18+ } ) ;
19+ it ( "terminates generators" , async ( ) => {
20+ const runtime = new Runtime ( ) ;
21+ const main = runtime . module ( ) ;
22+ const log = [ ] ;
23+ main . variable ( true ) . define ( [ ] , function * ( ) {
24+ try {
25+ while ( true ) yield ;
26+ } finally {
27+ log . push ( "return" ) ;
28+ }
29+ } ) ;
30+ await sleep ( ) ;
31+ runtime . dispose ( ) ;
32+ await sleep ( ) ;
33+ assert . deepStrictEqual ( log , [ "return" ] ) ;
34+ } ) ;
35+ } ) ;
You can’t perform that action at this time.
0 commit comments