Skip to content

Instantly share code, notes, and snippets.

View YouCanKeepSilence's full-sized avatar
:electron:

Egor Bogdanov YouCanKeepSilence

:electron:
View GitHub Profile
@YouCanKeepSilence
YouCanKeepSilence / broker.js
Last active December 21, 2020 09:23
Consumer broker with task delegation to workers on Node.js cluster
/*
Example of broker with worker cluster, you need this kind of architecture
when you have some gateway (API for example) with large amount of tasks (CPU tasks for example XML-string creation)
and want to delegate this tasks to workers (to improve speed of processing) without any additional brokers (kafka) usage.
*/
const cluster = require('cluster');
const express = require('express');
const http = require('http');
@YouCanKeepSilence
YouCanKeepSilence / sum_task.js
Created September 17, 2020 16:44
Interview task sum (curry-like)
/**
Напишите функцию sum которая умеет складывать числа. Пример работы:
sum(1); // => console: 1
sum(1)(2)(3); // => console: 1 3 6
*/
function sum(number) {
let counter = number;
console.log(counter);
return function a(number1) {