-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
35 lines (26 loc) · 983 Bytes
/
test.js
File metadata and controls
35 lines (26 loc) · 983 Bytes
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
const Ticker = require(".")
//Create ticker with ticking every 15ms
const ticker = new Ticker(15)
//Listening to events here
ticker.on("start", () => console.log("Ticker 1: started"))
.on("tick", () => console.log("Ticker 1: ticked"))
.on("stop", () => console.log("Ticker 1: stopped"))
//Starting the ticker
ticker.start()
//Waiting for the next tick
ticker.nextTick().then(() => {
console.log(`Ticker 1: called nextTick`)
//Create a second ticker ticking every 30ms
const ticker2 = new Ticker(30)
//Only attaching the tick event here
ticker2.on("tick", () => console.log("Ticker 2: ticked"))
//Starting the second ticker
ticker2.start()
ticker2.nextTick().then(() => {
//Killing both tickers and log to the console
ticker.stop()
ticker2.stop()
console.log("Ticker 2: called nextTick, killing Ticker 1 and Ticker 2")
})
})
//If a ticker still runs, the program won't exit