aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-06-09 17:31:08 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-06-09 17:31:08 +0800
commiteedf2e6b47ea57d87065af4a71a1ab61c088d7a2 (patch)
tree3daf7f87a4b764c4f88e3f04c5c358bb113abdbe /utils
parentd75bd7bacbd535951fbef392873df32f17801161 (diff)
downloadSoopyV2-eedf2e6b47ea57d87065af4a71a1ab61c088d7a2.tar.gz
SoopyV2-eedf2e6b47ea57d87065af4a71a1ab61c088d7a2.tar.bz2
SoopyV2-eedf2e6b47ea57d87065af4a71a1ab61c088d7a2.zip
+ make soulflow overlay use new soulflow api
+ util library for delaying function calls
Diffstat (limited to 'utils')
-rw-r--r--utils/delayUtils.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/utils/delayUtils.js b/utils/delayUtils.js
new file mode 100644
index 0000000..4c66d0f
--- /dev/null
+++ b/utils/delayUtils.js
@@ -0,0 +1,29 @@
+const { default: FlatQueue } = require("../datastructures/flatqueue")
+
+if (!global.delayThingSoopy) {
+
+ let functionQueue = new FlatQueue()
+ let functions = new Map()
+ let functionId = 0
+
+ function delay(time, callback) {
+ let id = functionId++
+ functionQueue.push(id, Date.now() + time)
+ functions.set(id, callback)
+ }
+
+ register("tick", () => {
+ while (functionQueue.length > 0 && Date.now() > functionQueue.peekValue()) {
+ let id = functionQueue.pop()
+
+ functions.get(id)()
+ functions.delete(id)
+ }
+ })
+
+ global.delayThingSoopy = {
+ delay
+ }
+}
+
+module.exports = global.delayThingSoopy