Created
September 23, 2018 10:47
-
-
Save DanishSiddiq/7be9cf6ac9d5116068ca252a4caea364 to your computer and use it in GitHub Desktop.
worker code for a long operation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default class AsyncListController { | |
| createList = async(req, res) => { | |
| await this.populateHugeList(); | |
| res.json({ ProcessId: 'Worker Process Id' + process.pid }); | |
| }; | |
| /* populate list with million elements | |
| */ | |
| populateHugeList = async() => { | |
| let lst = new Array(1e6); | |
| for(let k = 0; k < lst.length; k++) { | |
| lst[k] = k*5; | |
| } | |
| // after populating elements | |
| // fire a message informing master that list is created only in cluster mode | |
| process.send('List is created on worker process id ' + process.pid); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment