Instantly share code, notes, and snippets.
Guseyn Ismayylov Guseyn
🎵
Enjoying Writing Music With Words
Founder of Unison. Creator of EHTML. Creator of nodes.js (NodeJS Procedural Backend Framework with Cluster API based on HTTP/2.).
-
guseyn.com
- Tbilisi, Georgia
- https://guseyn.com
| function mapLimit (col, limit, mapFunc, doneFunc, newCol = [], index = { value: 0 }, freeThreads = { value: limit }) { |
| if (freeThreads.value > 0 && index.value < col.length) { |
| // Save current index |
| const curIndex = index.value |
| // Now the number of free threads is lower on 1 |
| freeThreads.value -= 1 |
| mapFunc((err, newItem) => { |
| if (err) { |
| // Smth bad happend, we call doneFunc with err |
| const assert = require('assert') |
| function flattenArray (nestedArray, resArray = []) { |
| for (let i = 0; i < nestedArray.length; i++) { |
| if (Array.isArray(nestedArray[i])) { |
| flattenArray(nestedArray[i], resArray) |
| } else { |
| resArray.push(nestedArray[i]) |
| } |
| } |
NewerOlder
