{"id":18544761,"url":"https://github.com/131/nyks","last_synced_at":"2025-04-09T19:31:23.100Z","repository":{"id":17719018,"uuid":"20544214","full_name":"131/nyks","owner":"131","description":"nodejs Exupery's style.","archived":false,"fork":false,"pushed_at":"2024-01-10T10:27:10.000Z","size":600,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-10T14:07:30.709Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/131.png","metadata":{"files":{"readme":"README-async.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-06-05T22:47:54.000Z","updated_at":"2024-04-23T14:25:01.295Z","dependencies_parsed_at":"2023-01-11T19:40:43.317Z","dependency_job_id":"94310ddd-c9c5-4fe7-a69c-35200e801876","html_url":"https://github.com/131/nyks","commit_stats":{"total_commits":583,"total_committers":8,"mean_commits":72.875,"dds":0.6226415094339622,"last_synced_commit":"932d92650eb3675c830a99497fd1fabf43f20ae9"},"previous_names":[],"tags_count":201,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fnyks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fnyks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fnyks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fnyks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/131","download_url":"https://codeload.github.com/131/nyks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223407841,"owners_count":17140572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T20:17:31.576Z","updated_at":"2024-11-06T20:17:32.015Z","avatar_url":"https://github.com/131.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async\n\nControl flow ala ES7 async/await with async.js (v2) signatures\n\n------\n\n## Table of Contents\n\n  * [Motivation](#Motivation)\n  * [API](#API)\n    * [eachLimit()](#eachLimit)\n    * [eachOfLimit()](#eachOfLimit)\n    * [each()](#each)\n    * [eachOf()](#eachOf)\n    * [eachSeries()](#eachSeries)\n    * [eachOfSeries()](#eachOfSeries)\n    * [retryUntil()](#retryUntil)\n    * [sleep()](#sleep)\n    * [timeout()](#timeout)\n    * [setImmediate()](#setImmediate)\n    * [queue()](#queue)\n    * [throttle()](#throttle)\n  * [Tests](#Tests)\n  * [TODO](#TODO)\n  * [Credits](#Credits)\n  * [Alternatives / relatives](#Alternatives)\n  * [Shoutbox, keywords, SEO love](#keywords)\n\n------\n\n\u003ca name=\"Motivation\"\u003e\u003c/a\u003e\n# Motivation\n\n[nyks/async](./async/) provide javascript async/await equivalent signatures of the excellent [async](https://github.com/caolan/async) workflow library.\n\nModule are exported in standard commonJS module format and written in strict format. (no transpilation required nor used).\nUse browserify if you need nyks/async modules in a browser environnement.\n\n**nyks/async** is not a wrapper on **async**, but rather leverages the full potential of native async/await \u0026 promises contract. Code tend to be small \u0026 very efficient (far more simplier than using callbacks), just give [nyks/async/queue.js](./async/queue.js) a look.\n\n\n## Addition to the async library signatures / promise pooling\n\n* Async functions cannot use arrow function binding style, yet it might be usefull to bind nyks/async closure, therefore, you can use an extra optional args to all signature to set async function binding context. (i.e. as in native [.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) )\n* Per design, it's easy to \"throttle\" a function that return a Promise ; checkout the \"throttle\" API for a way to make an ultra simple http request pooling.\n* async logic allow async/each to iterate through array AND objects. Per design sanify, nyks/async does not. Use each/eachLimit/eachSeries for arrays, eachOf/eachOfLimit/eachOfSeries for collections.\n\n------\n\n\u003ca name=\"API\"\u003e\u003c/a\u003e\n# API\n\n\u003ca name=\"eachLimit\"\u003e\u003c/a\u003e\n## eachLimit(arr, concurrency, thunk [, thisobj]) : Promise\n\nApplies the function 'thunk' to each item in 'arr', in parallel, with a limit async operations of 'concurrency' at a time. The 'thunk' is called with an item from the Array 'arr'.\n\n```javascript\nconst eachLimit = require('nyks/async/eachLimit');\n\n(async function() {\n\n  var stuffs = [1, 2, 3, 5, 6];\n\n  await eachLimit(stuffs, 2, async function(id) {\n    await dootherStuffs(id);\n  });\n\n})();\n```\n\n------\n\n\u003ca name=\"eachOfLimit\"\u003e\u003c/a\u003e\n## eachOfLimit(dict, concurrency, thunk [, thisobj]) : Promise\n\nApplies the function 'thunk' to each item of 'dict', in parallel, with a limit async operations of 'concurrency' at a time. The 'thunk' is called with an item from the Object 'dict'. \n\n```javascript\nconst eachOfLimit = require('nyks/async/eachOfLimit');\n\n(async function() {\n\n  var stuffs = {\n    'number' : 1,\n    'number' : 2,\n    'number' : 3,\n    'number' : 4\n  };\n\n  await eachOfLimit(stuffs, 2, async function(id, key) {\n    await dootherStuffs(id);\n  });\n\n})();\n```\n\n------\n\n\u003ca name=\"each\"\u003e\u003c/a\u003e\n## each(arr, thunk [, thisobj]) : Promise\n\nLike eachLimit with a concurrency of arr.length.\n\n```javascript\nconst each = require('nyks/async/each');\n\n(async function() {\n\n  var stuffs = [1, 2, 3, 5, 6];\n\n  await each(stuffs, async function(id) {\n    await dootherStuffs(id);\n  });\n\n})();\n```\n\n------\n\n\u003ca name=\"eachOf\"\u003e\u003c/a\u003e\n## eachOf(dict, thunk [, thisobj]) : Promise\n\nLike eachOfLimit with a concurrency of dict.length.\n\n```javascript\nconst eachOf = require('nyks/async/eachOf');\n\n(async function() {\n\n  var stuffs = {\n    'number' : 1,\n    'number' : 2,\n    'number' : 3,\n    'number' : 4\n  };\n\n  await eachOf(stuffs, async function(id, key) {\n    await dootherStuffs(id);\n  });\n\n})();\n```\n\n------\n\n\u003ca name=\"eachSeries\"\u003e\u003c/a\u003e\n## eachSeries(arr, thunk [, thisobj]) : Function\n\nLike eachLimit with a concurrency of 1.\n\n```javascript\nconst eachSeries = require('nyks/async/eachSeries');\n\n(async function() {\n\n  var stuffs = [1, 2, 3, 5, 6];\n\n  await eachSeries(stuffs, async function(id) {\n    await dootherStuffs(id);\n  });\n\n})();\n```\n\n------\n\n\u003ca name=\"eachOfSeries\"\u003e\u003c/a\u003e\n## eachOfSeries(dict, thunk [, thisobj]) : Function\n\nLike eachOfLimit with a concurrency of 1.\n\n```javascript\nconst eachOfSeries = require('nyks/async/eachOfSeries');\n\n(async function() {\n\n  var stuffs = {\n    'number' : 1,\n    'number' : 2,\n    'number' : 3,\n    'number' : 4\n  };\n\n  await eachOfSeries(stuffs, async function(id, key) {\n    await dootherStuffs(id);\n  });\n\n})();\n```\n\n------\n\n\u003ca name=\"retryUntil\"\u003e\u003c/a\u003e\n## retryUntil(thunk, timeout, delay, [, failure]) : Function\n\nRun thunk until it resolves a truthy value, until timeout is reached. Wait **delay** between each attempt. On timeout, reject with a generic \"Timeout\" error message (or the specified failure, if any).\n\n```javascript\nconst retryUntil = require('nyks/async/retryUntil');\n\n(async function() {\n\n  await tryUntil(async () =\u003e {\n    return net.connect(...)\n  }, 60 * 1000, 1000, 'Could not connect to remote socket');\n\n})();\n```\n\n\n\n\n\u003ca name=\"sleep\"\u003e\u003c/a\u003e\n## sleep(delay) : Promise\n\nsetTimeout as a promise.\n\n```javascript\nconst sleep = require('nyks/async/sleep');\n\n(async function() {\n\n  // this is now\n  await sleep(2000);\n  // this is now + 2 secondes\n\n})();\n```\n\n------\n\n\u003ca name=\"timeout\"\u003e\u003c/a\u003e\n## timeout(delay, [, reason]) : Promise\n\nreturn a Promise that reject after delay (with reason = 'timeout')\n\n```javascript\nconst timeout = require('nyks/async/timeout');\n\n(async function() {\n  await timeout(1000); // this will throw with message 'timeout'\n})();\n```\n\n------\n\n\u003ca name=\"setImmediate\"\u003e\u003c/a\u003e\n## setImmediate(fn) : Function\n\nCall a function in javascript next tick (using setImmediate API, or timeout 0 pollyfill)\n\n```javascript\nconst setImmediate = require('nyks/async/setImmediate');\n\n(async function() {\n\n  // this is now\n  await setImmediate();\n  // this is still now...\n\n})();\n```\n\n------\n\n\u003ca name=\"queue\"\u003e\u003c/a\u003e\n## queue(thunk, concurrency) : Object\n\nReturn a QueueObject you can push task into.\nWait for thunk to process task (wait for worker, if needed).\n\n```javascript\nconst fetch = require('node-fetch');\nconst queue = require('nyks/async/queue');\n\nvar q = queue(fetch, 1); //let's be nice\n\n(async function() {\n  await q.push(\"http://example.com/stuff.json\");\n})();\n\n(async function() {\n  await q.push(\"http://example.com/otherstuff.json\"); //will wait for stuff to be retrieved\n})();\n```\n\n------\n\n\u003ca name=\"throttle\"\u003e\u003c/a\u003e\n## throttle(thunk, concurrency) : Function\n\nThrottle any function that return a promise, sugar syntax helper for nyks/async/queue.\n\n```javascript\nconst fetch    = require('node-fetch');\nconst throttle = require('nyks/async/throttle');\n\nfetch = throttle(fetch, 1); //make fetch behave nicely\n\n(async function() {\n  await fetch(\"http://example.com/stuff.json\");\n})();\n\n(async function() {\n  await fetch(\"http://example.com/otherstuff.json\"); //will wait for stuff.json to be retrieved\n})();\n```\n\n------\n\n\u003ca name=\"Tests\"\u003e\u003c/a\u003e\n# Tests\nnyks/async is tested against async test suite (of course)\n\n------\n\n\u003ca nam=\"TODO\"\u003e\u003c/a\u003e\n# TODO\n* Get rich or die tryin'\n* write a working nyks/async/cargo (see [the challenge on stackoverflow](http://stackoverflow.com/questions/39069624))\n\n------\n\n\u003ca name=\"Credits\"\u003e\u003c/a\u003e\n# Credits\n* [131](https://github.com/131)\n* inspired from the excellent [async](https://github.com/caolan/async)\n* Derived from [async-co](https://github.com/131/async-co)\n\n------\n\n\u003ca name=\"Alternatives\"\u003e\u003c/a\u003e\n# Alternatives / relatives\n* [koa-async](https://github.com/eladnava/koa-async); a clever Promisify wrapper on top of async (but  not leveraging the full potential of ES7 async/await capabilities)\n* [caolan/async/asyncify.js](https://github.com/caolan/async/blob/master/lib/asyncify.js); goes the same as koa-async.\n* [es6-promise-pool](https://github.com/timdp/es6-promise-pool); equivalent to nyks/async/queue, with a different API\n\n------\n\n\u003ca name=\"keywords\"\u003e\u003c/a\u003e\n# Shoutbox, keywords, SEO love\nasync/await, co, nyks/async, promise, Promises, yield, async, queue, map, throttle, \"Let's have a beer \u0026 talk in Paris\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fnyks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F131%2Fnyks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fnyks/lists"}