Skip to content

Commit 7ed7a37

Browse files
authored
Merge pull request #642 from KenjiroAI/concurrency-robot-nodejs
Add Concurrency Robot for Node.js
2 parents c0a3fa6 + 28eab52 commit 7ed7a37

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

concurrency_robot/node.js/robot.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
// Node.js is async. Using event-driven programming is a good choice
4+
const EventEmitter = require('events');
5+
const event = new EventEmitter();
6+
7+
// Left
8+
event.on('left', () => {
9+
console.log('left');
10+
event.emit('right');
11+
});
12+
13+
// Right
14+
event.on('right', () => {
15+
console.log('right');
16+
event.emit('left');
17+
});
18+
19+
// Do first step
20+
event.emit('left');

0 commit comments

Comments
 (0)