1+ import {
2+ setTimeout , setImmediate , setInterval ,
3+ clearImmediate , clearInterval , clearTimeout
4+ } from "./timers.js" ;
5+ import { world } from "mojang-minecraft" ;
6+
7+ function stdout ( ...data : any [ ] ) : any {
8+ return world . getDimension ( "overworld" ) . runCommand ( `say §r` + data . join ( " " ) ) ;
9+ } ;
10+ function stderr ( ...data : any [ ] ) : any {
11+ return world . getDimension ( "overworld" ) . runCommand ( `say §c` + data . join ( " " ) ) ;
12+ } ;
13+
14+ // timeout test
15+ setTimeout ( function ( arg , arg1 ) {
16+ stdout ( "arg" , arg , "arg1" , arg1 ) ;
17+ } , 1000 , "hello" , "world" , 1 ) ;
18+
19+ stdout ( "setTimeout passed" ) ;
20+
21+ // cleartimeout test
22+ let timeout2 = setTimeout ( function ( ) {
23+ stderr ( "clearTimeout failed" ) ;
24+ } , 1000 ) ;
25+
26+ clearTimeout ( timeout2 ) ;
27+
28+ stdout ( "clearTimeout passed" ) ;
29+
30+ // setinterval test
31+ let interval = setInterval ( function ( arg , arg1 ) {
32+ stdout ( "arg" , arg , "arg1" , arg1 ) ;
33+ } , 1000 , "set" , "interval" , 1 ) ;
34+
35+ stdout ( "setTimeout passed" ) ;
36+
37+ // clearinterval test
38+ interval . _onTimeout = ( ) => {
39+ stderr ( "clearInterval failed" ) ;
40+ } ;
41+ clearInterval ( interval ) ;
42+
43+ stdout ( "clearInterval passed" ) ;
44+
45+ // setimmediate test
46+ setImmediate ( function ( ) {
47+ stdout ( "setImmediate passed" ) ;
48+ } ) ;
49+
50+ // clearimmediate test
51+ let immediate = setImmediate ( function ( ) {
52+ stderr ( "setImmediate failed" ) ;
53+ } ) ;
54+ clearImmediate ( immediate ) ;
55+
56+ stdout ( "clearImmediate passed" ) ;
0 commit comments