FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-cli/lib/queue.js at master · heyunjun/leetcode-cli · GitHub
heyunjun
/
leetcode-cli
Public
forked from
skygragon/leetcode-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-cli
/
lib
/
queue.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (30 loc) · 723 Bytes
Breadcrumbs
leetcode-cli
/
lib
/
queue.js
Copy path
File metadata and controls
38 lines (30 loc) · 723 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
var
_
=
require
(
'underscore'
)
;
var
config
=
require
(
'./config'
)
;
var
queue
=
{
}
;
function
workerRun
(
ctx
)
{
// no more tasks, quit now
if
(
ctx
.
tasks
.
length
===
0
)
{
if
(
--
ctx
.
workers
===
0
&&
ctx
.
cb
)
ctx
.
cb
(
ctx
.
error
)
;
return
;
}
var
task
=
ctx
.
tasks
.
shift
(
)
;
ctx
.
doTask
(
task
,
function
(
e
)
{
if
(
e
)
ctx
.
error
=
e
;
// TODO: could retry failed task here.
setImmediate
(
workerRun
,
ctx
)
;
}
)
;
}
queue
.
run
=
function
(
tasks
,
doTask
,
cb
)
{
var
ctx
=
{
tasks
:
_
.
clone
(
tasks
)
,
doTask
:
doTask
,
cb
:
cb
,
workers
:
config
.
MAX_WORKERS
||
1
,
error
:
null
}
;
for
(
var
i
=
0
;
i
<
ctx
.
workers
;
++
i
)
{
setImmediate
(
workerRun
,
ctx
)
;
}
}
;
module
.
exports
=
queue
;
Back
|
FazBrowse Home
|
New Git URL