forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimers.d.ts
More file actions
113 lines (113 loc) · 3.89 KB
/
timers.d.ts
File metadata and controls
113 lines (113 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* @license MIT
* @author JaylyMC
* @project https://github.com/JaylyDev/GametestDB/
*/
/**
* The `timer` module exposes a global API for scheduling functions to
* be called at some future period of time.
*
* The timer functions within this script implement a similar API as the timers API
* provided by Web Browsers and Node.js but use a different internal implementation that is
* built for QuickJS, specifically for Minecraft Bedrock Edition script APIs (experimental).
*/
/**
* Internal timer class that can be used to reference
* the set Timeout or Interval object.
*/
declare class Timer {
_idleTimeout: number;
_idleStart: number;
_onTimeout: (...args: any) => void;
_repeat: boolean;
_destroyed: boolean;
constructor(idleTimeout: number, idleStart: number, onTimeout: (...args: any) => void, repeat: boolean, destroyed: boolean, ...args: any);
}
declare class Timeout extends Timer {
_idleTimeout: number;
_idleStart: number;
_onTimeout: (...args: any) => void;
_repeat: boolean;
_destroyed: boolean;
constructor(idleTimeout: number, idleStart: number, onTimeout: (...args: any) => void, repeat: boolean, destroyed: boolean, ...args: any);
}
/**
* Internal timer class that can be used to reference
* the set Immediate object.
*/
declare class Immediate {
_onImmediate: (...args: any) => void;
_argv: any[];
_destroyed: boolean;
constructor(onImmediate: (...args: any) => void, ...args: any);
}
/**
* @param callback a function to execute as its first argument
* @param ms the millisecond delay defined as a number as the second argument.
* @param args Additional arguments may also be included and these will be passed on to the function.
*
* @example
* ```js
* function myFunc(arg) {
* console.log(`arg was => ${arg}`);
* }
*
* setTimeout(myFunc, 1500, 'funky');
* ```
*/
declare function setTimeout(callback: (...args: any) => void, ms?: number, ...args: any): Timeout;
/**
* By passing said object into the respective clear function,
* execution of that object will be halted completely.
* @param timeoutId Timeout object returned by `setTimeout()`
*/
declare function clearTimeout(timeoutId: Timeout | undefined): void;
/**
* @param callback Takes a function argument that will run an infinite number of times
* @param ms A given millisecond delay as the second argument
* @param args Just like `setTimeout()`, additional arguments can be added beyond the delay,
* and these will be passed on to the function call.
* @example
* ```js
* function intervalFunc() {
* console.log('Cant stop me now!');
* }
*
* setInterval(intervalFunc, 1500);
* ```
*/
declare function setInterval(callback: (...args: any) => void, ms?: number, ...args: any): Timer;
/**
* By passing said object into the respective clear function,
* execution of that object will be halted completely.
* @param intervalId Interval object returned by `setInterval()`
*/
declare function clearInterval(intervalId: Timer | undefined): void;
/**
* @param callback The function to execute
* @param args Any subsequent arguments will be passed to the function when it is executed.
*
* @example
* ```js
* console.log('before immediate');
*
* setImmediate((arg) => {
* console.log(`executing immediate: ${arg}`);
* }, 'so immediate');
*
* console.log('after immediate');
* ```
*/
declare function setImmediate(callback: (args: void) => void, ...args: any): Immediate;
/**
* By passing said object into the respective clear function,
* execution of that object will be halted completely.
* @param immediateId Immediate object returned by `setImmediate()`
*/
declare function clearImmediate(immediateId: Immediate | undefined): void;
/**
* Timers function are exported so developers
* can choose which set of functions they want to
* withdraw from the `timers` module.
*/
export { setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate };