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
| var cluster = require('cluster'), | |
| app = require('./app'); | |
| var workers = {}, | |
| count = require('os').cpus().length; | |
| function spawn(){ | |
| var worker = cluster.fork(); | |
| workers[worker.pid] = worker; | |
| return worker; |
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
| ... | |
| app.use(function(req, res, next){ | |
| if (app.get('graceful_shutdown') === true) { | |
| res.set('Connection', 'close'); | |
| } | |
| next(); | |
| }); | |
| app.set('graceful_shutdown_start', function() { |
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
| // Require libraries | |
| var os = require("os"); | |
| var fs = require("fs"); | |
| var readline = require("readline"); | |
| var cluster = require("cluster"); | |
| var express = require("express"); | |
| var site = express(); | |
| // Var up, bro | |
| var i, read; |
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
| (function () { | |
| 'use strict'; | |
| var cluster = require('cluster'), | |
| http = require('http'), | |
| os = require('os'), | |
| /* | |
| * ClusterServer object |
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
| /* | |
| Let us re-create `Promise.all` | |
| `Promise.all` method returns a promise that resolves when all of the promises in the iterable argument have resolved, | |
| or rejects with the reason of the first passed promise that rejects. | |
| Read more about `Promise.all` on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all | |
| A basic example would be something like this: | |
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
| async function selectPizza() { | |
| const pizzaData = await getPizzaData() // асинхронный вызов | |
| const chosenPizza = choosePizza() // синхронный вызов | |
| await addPizzaToCart(chosenPizza) // асинхронный вызов | |
| } | |
| async function selectDrink() { | |
| const drinkData = await getDrinkData() // асинхронный вызов | |
| const chosenDrink = chooseDrink() // синхронный вызов | |
| await addDrinkToCart(chosenDrink) // асинхронный вызов |
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
| /** Async version of Array.prototype.reduce() | |
| * await reduce(['/foo', '/bar', '/baz'], async (acc, v) => { | |
| * acc[v] = await (await fetch(v)).json(); | |
| * return acc; | |
| * }, {}); | |
| */ | |
| export async function reduce(arr, fn, val, pure) { | |
| for (let i=0; i<arr.length; i++) { | |
| let v = await fn(val, arr[i], i, arr); | |
| if (pure!==false) val = v; |
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
| async.parallel({ | |
| friends : function(cb) { getFriends(cb); }, | |
| messages : function(cb) { getMessages(cb); }, | |
| notifications : function(cb) { getNotifications(cb); } | |
| }, function(e, results) { | |
| if( e ) handleError(e); | |
| doSomethingWith(results); | |
| }); |
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
| 'use restrict'; | |
| /** | |
| * Module dependences. | |
| */ | |
| var mongoose = require('mongoose'); | |
| /** | |
| * load up the material model. | |
| */ |
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
| 'use strict'; | |
| /** | |
| * Module dependencies. | |
| */ | |
| const mongoose = require('mongoose'); | |
| const notify = require('../mailer'); | |
| // const Imager = require('imager'); |