forked from github/codeql-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSync.coffee
More file actions
28 lines (27 loc) · 725 Bytes
/
Copy pathSync.coffee
File metadata and controls
28 lines (27 loc) · 725 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
DLList = require "./DLList"
class Sync
constructor: (@name, @Promise) ->
@_running = 0
@_queue = new DLList()
isEmpty: -> @_queue.length == 0
_tryToRun: ->
if (@_running < 1) and @_queue.length > 0
@_running++
{ task, args, resolve, reject } = @_queue.shift()
cb = try
returned = await task args...
() -> resolve returned
catch error
() -> reject error
@_running--
@_tryToRun()
cb()
schedule: (task, args...) =>
resolve = reject = null
promise = new @Promise (_resolve, _reject) ->
resolve = _resolve
reject = _reject
@_queue.push { task, args, resolve, reject }
@_tryToRun()
promise
module.exports = Sync