FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Generator/JavaScript/5-producer-consumer-send.js at master · HowProgrammingWorks/Generator · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
HowProgrammingWorks
/
Generator
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
17
Star
19
Code
Issues
1
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Generator
/
JavaScript
/
5-producer-consumer-send.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (36 loc) · 680 Bytes
Breadcrumbs
Generator
/
JavaScript
/
5-producer-consumer-send.js
Copy path
File metadata and controls
42 lines (36 loc) · 680 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
39
40
41
42
'use strict'
;
function
*
sleep
(
interval
)
{
const
start
=
new
Date
(
)
;
while
(
new
Date
(
)
-
start
<
interval
)
{
yield
;
}
}
function
*
produce
(
consumer
)
{
while
(
true
)
{
yield
*
sleep
(
500
)
;
consumer
.
next
(
Math
.
random
(
)
)
;
}
}
function
*
consume
(
)
{
let
count
=
0
;
let
sum
=
0
;
while
(
true
)
{
const
data
=
yield
;
count
++
;
sum
+=
data
;
console
.
log
(
`Got data:
${
data
}
\n`
+
`Count:
${
count
}
\n`
+
`Sum:
${
sum
}
\n`
+
`Average:
${
sum
/
count
}
\n`
,
)
;
}
}
const
consumer
=
consume
(
)
;
const
producer
=
produce
(
consumer
)
;
consumer
.
next
(
)
;
const
step
=
(
)
=>
{
producer
.
next
(
)
;
setImmediate
(
step
)
;
}
;
step
(
)
;
Back
|
FazBrowse Home
|
New Git URL