Platform
Resources
Pricing
Sign in
Get started
Fil
Vocateur.
Workspace
Fork
Published
Hello
By
Fil
Edited
Jun 1, 2020
Fork of
Hello async-pool
2 stars
Insert cell
Insert cell
Insert cell
task
=
(
i
,
state
)
=>
new
Promise
(
async
(
resolve
,
reject
)
=>
{
state
.
c
++
;
await
Promises
.
delay
(
50
)
;
const
c
=
state
.
c
;
// measure concurrency in the middle of the task’s run
await
Promises
.
delay
(
50
+
50
*
Math
.
random
(
)
)
;
state
.
c
--
;
resolve
(
c
)
;
}
)
Insert cell
Insert cell
{
const
state
=
{
c
:
0
}
;
const
results
=
await
Promise
.
all
(
Array
.
from
(
{
length
:
20
}
,
(
_
,
i
)
=>
task
(
i
,
state
)
)
)
;
return
results
;
}
Insert cell
Insert cell
{
const
state
=
{
c
:
0
}
;
const
queue
=
new
PQueue
(
{
concurrency
:
4
}
)
;
return
queue
.
addAll
(
Array
.
from
(
{
length
:
20
}
,
(
_
,
i
)
=>
i
)
.
map
(
i
=>
(
)
=>
task
(
i
,
state
)
)
)
;
}
Insert cell
Insert cell
PQueue
=
(
await
require
(
"https://bundle.run/p-queue"
)
)
.
default
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
task
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
PQueue
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML