{"id":24686931,"url":"https://github.com/rickypc/timeable-promise","last_synced_at":"2025-10-29T17:01:50.676Z","repository":{"id":48923251,"uuid":"199789811","full_name":"rickypc/timeable-promise","owner":"rickypc","description":"Various asynchronous operations with timeout support","archived":false,"fork":false,"pushed_at":"2023-05-10T21:59:05.000Z","size":104,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T11:05:40.493Z","etag":null,"topics":["asynchronous","helper","promise","support","time","timeable","timeout","utility","wait"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/timeable-promise","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rickypc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-31T06:03:22.000Z","updated_at":"2024-05-31T08:53:36.000Z","dependencies_parsed_at":"2022-09-24T00:11:24.407Z","dependency_job_id":null,"html_url":"https://github.com/rickypc/timeable-promise","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Ftimeable-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Ftimeable-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Ftimeable-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Ftimeable-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rickypc","download_url":"https://codeload.github.com/rickypc/timeable-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235726364,"owners_count":19035841,"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":["asynchronous","helper","promise","support","time","timeable","timeout","utility","wait"],"created_at":"2025-01-26T16:17:11.731Z","updated_at":"2025-10-08T15:31:53.821Z","avatar_url":"https://github.com/rickypc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Version](https://img.shields.io/npm/v/timeable-promise)](https://bit.ly/2YFweqU)\n[![Downloads](https://img.shields.io/npm/dt/timeable-promise)](https://bit.ly/2YFweqU)\n[![Dependency Status](https://img.shields.io/librariesio/github/rickypc/timeable-promise)](https://bit.ly/3MUJErG)\n[![Code Style](https://img.shields.io/badge/code%20style-Airbnb-red)](https://bit.ly/2JYN1gk)\n[![Build](https://img.shields.io/github/actions/workflow/status/rickypc/timeable-promise/validations.yml)](https://bit.ly/43aA0qF)\n[![Coverage](https://img.shields.io/codecov/c/github/rickypc/timeable-promise)](https://bit.ly/2LPRiVj)\n[![Vulnerability](https://img.shields.io/snyk/vulnerabilities/github/rickypc/timeable-promise)](https://bit.ly/2yP3kGa)\n[![License](https://img.shields.io/npm/l/timeable-promise)](https://bit.ly/2yi7gyO)\n\nTimeable Promise\n================\n\nVarious asynchronous operations with timeout support.\n\nInstallation\n-\n\n```bash\n$ yarn add timeable-promise\n# or\n$ npm install --save timeable-promise\n```\n\nAPI Reference\n-\nVarious asynchronous operations with timeout support.\n\n**See**: [Promise](https://mzl.la/2MQJhPC)  \n**Example**  \n```js\nconst {\n  chunk,\n  concurrent,\n  concurrents,\n  consecutive,\n  consecutives,\n  parallel,\n  poll,\n  sequential,\n  sleep,\n  toNumber,\n  untilSettledOrTimedOut,\n  waitFor,\n} = require('timeable-promise');\n\n// ---------- chunk ----------\nconst chunked = chunk([1, 2, 3, 4], 2);\nconsole.log('chunked: ', chunked);\n\n// ---------- concurrent ----------\nconst concurrentSettled = await concurrent([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('concurrent settled: ', concurrentSettled);\n\n// ---------- concurrents ----------\nconst concurrentsSettled = await concurrents([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('concurrents settled: ', concurrentsSettled);\n\n// ---------- consecutive ----------\nconst consecutiveSettled = await consecutive([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('consecutive settled: ', consecutiveSettled);\n\n// ---------- consecutives ----------\nconst consecutivesSettled = await consecutives([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('consecutives settled: ', consecutivesSettled);\n\n// ---------- parallel ----------\nconst parallelSettled = await parallel([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('parallel settled: ', parallelSettled);\n\n// ---------- poll ----------\nconst timer = poll((stopped) =\u003e {\n  // Do something promising here...\n  if (!stopped()) {\n    // Do something when polling is not stopped...\n  }\n}, 100);\nsetTimeout(() =\u003e {\n  // Simulate the end of polling.\n  timer.stop();\n}, 1000);\n\n// ---------- sequential ----------\nconst sequentialSettled = await sequential([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('sequential settled: ', sequentialSettled);\n\n// ---------- sleep ----------\nconsole.time('sleep');\n// Sleep for 1s.\nawait sleep(1000);\nconsole.timeEnd('sleep');\n\n// ---------- toNumber ----------\nconst converted = toNumber('1');\nconsole.log('converted: ', 1);\n\n// ---------- untilSettledOrTimedOut ----------\nconst response = await untilSettledOrTimedOut((resolve, reject, pending) =\u003e {\n  // Promise executor with extra `pending` param to check if promise is not\n  // timed-out yet.\n  if (pending()) {\n    resolve(true);\n  }\n}, (resolve, reject) =\u003e {\n  // Timeout executor with option to either resolve or reject the promise.\n  reject(Error('error'));\n}, 5000)\n  .catch(ex =\u003e console.log('nay :(', ex));\nconsole.log(`resolved with ${response}, yay!`);\n\n// ---------- waitFor ----------\n// Long process running...\nlet inflight = true\nconst predicate = () =\u003e !inflight;\nconst timeout = 5000;\nsetTimeout(() =\u003e {\n  // Long process done.\n  inflight = false;\n}, 1000);\nconsole.time('waitFor');\nawait waitFor(predicate, timeout);\nconsole.timeEnd('waitFor');\n```\n\n* [timeable-promise](#module_timeable-promise)\n    * [.chunk(array, [size])](#module_timeable-promise.chunk) ⇒ \u003ccode\u003eArray\u003c/code\u003e\n    * [.concurrent(array, executor, [concurrency])](#module_timeable-promise.concurrent) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\n        * [~executor](#module_timeable-promise.concurrent..executor) : \u003ccode\u003efunction\u003c/code\u003e\n        * [~settled](#module_timeable-promise.concurrent..settled) : \u003ccode\u003eobject\u003c/code\u003e\n    * [.concurrents(array, executor, [concurrency])](#module_timeable-promise.concurrents) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\n    * [.consecutive(array, executor, [concurrency])](#module_timeable-promise.consecutive) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\n        * [~executor](#module_timeable-promise.consecutive..executor) : \u003ccode\u003efunction\u003c/code\u003e\n        * [~settled](#module_timeable-promise.consecutive..settled) : \u003ccode\u003eobject\u003c/code\u003e\n    * [.consecutives(array, executor, [concurrency])](#module_timeable-promise.consecutives) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\n    * [.parallel(array, executor, [concurrency])](#module_timeable-promise.parallel) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\n    * [.poll(executor, [interval], [immediately])](#module_timeable-promise.poll) ⇒ [\u003ccode\u003etimer\u003c/code\u003e](#module_timeable-promise.poll..timer)\n        * [~executor](#module_timeable-promise.poll..executor) : \u003ccode\u003efunction\u003c/code\u003e\n        * [~timer](#module_timeable-promise.poll..timer) : \u003ccode\u003eobject\u003c/code\u003e\n    * [.sequential(array, executor, [concurrency])](#module_timeable-promise.sequential) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\n    * [.sleep(timeout)](#module_timeable-promise.sleep) ⇒ \u003ccode\u003ePromise.\u0026lt;void\u0026gt;\u003c/code\u003e\n    * [.toNumber(value, [defaultValue])](#module_timeable-promise.toNumber) ⇒ \u003ccode\u003enumber\u003c/code\u003e\n    * [.untilSettledOrTimedOut(executor, timeoutExecutor, timeout)](#module_timeable-promise.untilSettledOrTimedOut) ⇒ \u003ccode\u003ePromise.\u0026lt;\\*\u0026gt;\u003c/code\u003e\n        * [~executor](#module_timeable-promise.untilSettledOrTimedOut..executor) : \u003ccode\u003efunction\u003c/code\u003e\n        * [~timeoutExecutor](#module_timeable-promise.untilSettledOrTimedOut..timeoutExecutor) : \u003ccode\u003efunction\u003c/code\u003e\n    * [.waitFor(predicate, timeout, [interval])](#module_timeable-promise.waitFor) ⇒ \u003ccode\u003ePromise.\u0026lt;void\u0026gt;\u003c/code\u003e\n\n\u003ca name=\"module_timeable-promise.chunk\"\u003e\u003c/a\u003e\n\n### timeable-promise.chunk(array, [size]) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nSplits the `array` into groups of `size`.\n             The final chunk would be the remaining elements.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - The chunked array.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The original array. |\n| [size] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The group size. |\n\n**Example**  \n```js\nconst { chunk } = require('timeable-promise');\nconst chunked = chunk([1, 2, 3, 4], 2);\nconsole.log('chunked: ', chunked);\n```\n\u003ca name=\"module_timeable-promise.concurrent\"\u003e\u003c/a\u003e\n\n### timeable-promise.concurrent(array, executor, [concurrency]) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\nRun `executor` on all `array` items concurrently.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e - The concurrent outcome objects.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The array items to be processed by executor. |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.concurrent..executor) |  | Executor function. |\n| [concurrency] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The max concurrent execution. |\n\n**Example**  \n```js\nconst { concurrent } = require('timeable-promise');\nconst concurrentSettled = await concurrent([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('concurrent settled: ', concurrentSettled);\n```\n\n* [.concurrent(array, executor, [concurrency])](#module_timeable-promise.concurrent) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\n    * [~executor](#module_timeable-promise.concurrent..executor) : \u003ccode\u003efunction\u003c/code\u003e\n    * [~settled](#module_timeable-promise.concurrent..settled) : \u003ccode\u003eobject\u003c/code\u003e\n\n\u003ca name=\"module_timeable-promise.concurrent..executor\"\u003e\u003c/a\u003e\n\n#### concurrent~executor : \u003ccode\u003efunction\u003c/code\u003e\nExecutor function that will be executed concurrently.\n\n**Kind**: inner typedef of [\u003ccode\u003econcurrent\u003c/code\u003e](#module_timeable-promise.concurrent)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| value | \u003ccode\u003e\\*\u003c/code\u003e | The current value being processed in the array. |\n| index | \u003ccode\u003enumber\u003c/code\u003e | The index of the current value being processed in the array. |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The array that is being processed concurrently. |\n\n**Example**  \n```js\nconst executor = (value, index, array) =\u003e {\n  // Do something promising here...\n};\n```\n\u003ca name=\"module_timeable-promise.concurrent..settled\"\u003e\u003c/a\u003e\n\n#### concurrent~settled : \u003ccode\u003eobject\u003c/code\u003e\nConcurrent outcome object.\n\n**Kind**: inner typedef of [\u003ccode\u003econcurrent\u003c/code\u003e](#module_timeable-promise.concurrent)  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| reason | \u003ccode\u003eError\u003c/code\u003e | The exception object. |\n| status | \u003ccode\u003estring\u003c/code\u003e | The outcome status. |\n| value | \u003ccode\u003e\\*\u003c/code\u003e | The outcome value. |\n\n\u003ca name=\"module_timeable-promise.concurrents\"\u003e\u003c/a\u003e\n\n### timeable-promise.concurrents(array, executor, [concurrency]) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\nRun `executor` on all `array` groups concurrently.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e - The concurrent outcome objects.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The array groups to be processed by executor. |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.concurrent..executor) |  | Executor function. |\n| [concurrency] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The max concurrent execution. |\n\n**Example**  \n```js\nconst { concurrents } = require('timeable-promise');\nconst concurrentsSettled = await concurrents([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('concurrents settled: ', concurrentsSettled);\n```\n\u003ca name=\"module_timeable-promise.consecutive\"\u003e\u003c/a\u003e\n\n### timeable-promise.consecutive(array, executor, [concurrency]) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\nRun `executor` on all `array` items consecutively.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e - The consecutive outcome objects.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The array items to be processed by executor. |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.consecutive..executor) |  | Executor function. |\n| [concurrency] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The max consecutive execution. |\n\n**Example**  \n```js\nconst { consecutive } = require('timeable-promise');\nconst consecutiveSettled = await consecutive([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('consecutive settled: ', consecutiveSettled);\n```\n\n* [.consecutive(array, executor, [concurrency])](#module_timeable-promise.consecutive) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\n    * [~executor](#module_timeable-promise.consecutive..executor) : \u003ccode\u003efunction\u003c/code\u003e\n    * [~settled](#module_timeable-promise.consecutive..settled) : \u003ccode\u003eobject\u003c/code\u003e\n\n\u003ca name=\"module_timeable-promise.consecutive..executor\"\u003e\u003c/a\u003e\n\n#### consecutive~executor : \u003ccode\u003efunction\u003c/code\u003e\nExecutor function that will be executed consecutively.\n\n**Kind**: inner typedef of [\u003ccode\u003econsecutive\u003c/code\u003e](#module_timeable-promise.consecutive)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| value | \u003ccode\u003e\\*\u003c/code\u003e | The current value being processed in the array. |\n| index | \u003ccode\u003enumber\u003c/code\u003e | The index of the current value being processed in the array. |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The array that is being processed consecutively. |\n| accumulator | \u003ccode\u003eArray\u003c/code\u003e | The outcome array from previous call to this executor. |\n\n**Example**  \n```js\nconst executor = (value, index, array, accumulator) =\u003e {\n  // Do something promising here...\n};\n```\n\u003ca name=\"module_timeable-promise.consecutive..settled\"\u003e\u003c/a\u003e\n\n#### consecutive~settled : \u003ccode\u003eobject\u003c/code\u003e\nConsecutive outcome object.\n\n**Kind**: inner typedef of [\u003ccode\u003econsecutive\u003c/code\u003e](#module_timeable-promise.consecutive)  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| reason | \u003ccode\u003eError\u003c/code\u003e | The exception object. |\n| status | \u003ccode\u003estring\u003c/code\u003e | The outcome status. |\n| value | \u003ccode\u003e\\*\u003c/code\u003e | The outcome value. |\n\n\u003ca name=\"module_timeable-promise.consecutives\"\u003e\u003c/a\u003e\n\n### timeable-promise.consecutives(array, executor, [concurrency]) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\nRun `executor` on all `array` groups consecutively.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e - The consecutive outcome objects.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The array groups to be processed by executor. |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.consecutive..executor) |  | Executor function. |\n| [concurrency] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The max consecutive execution. |\n\n**Example**  \n```js\nconst { consecutives } = require('timeable-promise');\nconst consecutivesSettled = await consecutives([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('consecutives settled: ', consecutivesSettled);\n```\n\u003ca name=\"module_timeable-promise.parallel\"\u003e\u003c/a\u003e\n\n### timeable-promise.parallel(array, executor, [concurrency]) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e\nProvide parallel execution with `concurrency` support.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.concurrent~settled\u0026gt;\u0026gt;\u003c/code\u003e - The parallel outcome objects.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The array that is being processed in parallel. |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.concurrent..executor) |  | Executor function. |\n| [concurrency] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The max concurrent execution. |\n\n**Example**  \n```js\nconst { parallel } = require('timeable-promise');\nconst parallelSettled = await parallel([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('parallel settled: ', parallelSettled);\n```\n\u003ca name=\"module_timeable-promise.poll\"\u003e\u003c/a\u003e\n\n### timeable-promise.poll(executor, [interval], [immediately]) ⇒ [\u003ccode\u003etimer\u003c/code\u003e](#module_timeable-promise.poll..timer)\nProvide polling support without congestion when `executor`\n             takes longer than `interval`.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: [\u003ccode\u003etimer\u003c/code\u003e](#module_timeable-promise.poll..timer) - The return object with stop function.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.poll..executor) |  | Executor function. |\n| [interval] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e1000\u003c/code\u003e | Delay interval. |\n| [immediately] | \u003ccode\u003eboolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | Run executor immediately in the beginning. |\n\n**Example**  \n```js\nconst { poll } = require('timeable-promise');\nconst timer = poll((stopped) =\u003e {\n  // Do something promising here...\n  if (!stopped()) {\n    // Do something when polling is not stopped...\n  }\n}, 100);\nsetTimeout(() =\u003e {\n  // Simulate the end of polling.\n  timer.stop();\n}, 1000);\n```\n\n* [.poll(executor, [interval], [immediately])](#module_timeable-promise.poll) ⇒ [\u003ccode\u003etimer\u003c/code\u003e](#module_timeable-promise.poll..timer)\n    * [~executor](#module_timeable-promise.poll..executor) : \u003ccode\u003efunction\u003c/code\u003e\n    * [~timer](#module_timeable-promise.poll..timer) : \u003ccode\u003eobject\u003c/code\u003e\n\n\u003ca name=\"module_timeable-promise.poll..executor\"\u003e\u003c/a\u003e\n\n#### poll~executor : \u003ccode\u003efunction\u003c/code\u003e\nExecutor function that is executed immediately by the Promise implementation.\n\n**Kind**: inner typedef of [\u003ccode\u003epoll\u003c/code\u003e](#module_timeable-promise.poll)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| stopped | \u003ccode\u003efunction\u003c/code\u003e | True if polling is stopped, otherwise false. |\n\n**Example**  \n```js\nconst executor = (stopped) =\u003e {\n  // Do something promising here...\n  if (!stopped()) {\n    // Do something when polling is not stopped...\n  }\n};\n```\n\u003ca name=\"module_timeable-promise.poll..timer\"\u003e\u003c/a\u003e\n\n#### poll~timer : \u003ccode\u003eobject\u003c/code\u003e\nTimer object containing the polling stop function.\n\n**Kind**: inner typedef of [\u003ccode\u003epoll\u003c/code\u003e](#module_timeable-promise.poll)  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| stop | \u003ccode\u003efunction\u003c/code\u003e | The polling stop function. |\n\n\u003ca name=\"module_timeable-promise.sequential\"\u003e\u003c/a\u003e\n\n### timeable-promise.sequential(array, executor, [concurrency]) ⇒ \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e\nProvide sequential execution with `concurrency` support.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Array.\u0026lt;module:timeable-promise.consecutive~settled\u0026gt;\u0026gt;\u003c/code\u003e - The sequential outcome objects.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The array that is being processed in sequential. |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.consecutive..executor) |  | Executor function. |\n| [concurrency] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The max consecutive execution. |\n\n**Example**  \n```js\nconst { sequential } = require('timeable-promise');\nconst sequentialSettled = await sequential([...], (value, index, array) =\u003e {\n  // Do something promising here...\n  return value;\n});\nconsole.log('sequential settled: ', sequentialSettled);\n```\n\u003ca name=\"module_timeable-promise.sleep\"\u003e\u003c/a\u003e\n\n### timeable-promise.sleep(timeout) ⇒ \u003ccode\u003ePromise.\u0026lt;void\u0026gt;\u003c/code\u003e\nProvide sleep support.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| timeout | \u003ccode\u003enumber\u003c/code\u003e | Timeout. |\n\n**Example**  \n```js\nconst { sleep } = require('timeable-promise');\nconsole.time('sleep');\n// Sleep for 1s.\nawait sleep(1000);\nconsole.timeEnd('sleep');\n```\n\u003ca name=\"module_timeable-promise.toNumber\"\u003e\u003c/a\u003e\n\n### timeable-promise.toNumber(value, [defaultValue]) ⇒ \u003ccode\u003enumber\u003c/code\u003e\nConverts `value` to number.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003enumber\u003c/code\u003e - The converted number.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| value | \u003ccode\u003e\\*\u003c/code\u003e |  | The value to be converted to number. |\n| [defaultValue] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | The default number. |\n\n**Example**  \n```js\nconst { toNumber } = require('timeable-promise');\nconst converted = toNumber('1');\nconsole.log('converted: ', 1);\n```\n\u003ca name=\"module_timeable-promise.untilSettledOrTimedOut\"\u003e\u003c/a\u003e\n\n### timeable-promise.untilSettledOrTimedOut(executor, timeoutExecutor, timeout) ⇒ \u003ccode\u003ePromise.\u0026lt;\\*\u0026gt;\u003c/code\u003e\nProvide `timeout` support on Promise object.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;\\*\u0026gt;\u003c/code\u003e - Resolve or reject response value.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| executor | [\u003ccode\u003eexecutor\u003c/code\u003e](#module_timeable-promise.untilSettledOrTimedOut..executor) | Executor function. |\n| timeoutExecutor | [\u003ccode\u003etimeoutExecutor\u003c/code\u003e](#module_timeable-promise.untilSettledOrTimedOut..timeoutExecutor) | Timeout executor function. |\n| timeout | \u003ccode\u003enumber\u003c/code\u003e | Timeout. |\n\n**Example**  \n```js\nconst { untilSettledOrTimedOut } = require('timeable-promise');\nconst executor = (resolve, reject, pending) =\u003e {\n  // Do something promising here...\n  if (pending()) {\n    try {\n      // Do something more promising here...\n      resolve(true);\n    } catch (ex) {\n      reject(false);\n    }\n  }\n};\nconst timeoutExecutor = (resolve, reject) =\u003e {\n  try {\n    resolve(true);\n  } catch (ex) {\n    reject(false);\n  }\n};\nconst timeout = 5000;\nconst response = await untilSettledOrTimedOut(executor, timeoutExecutor, timeout)\n  .catch(ex =\u003e console.log('nay :(', ex));\nconsole.log(`resolved with ${response}, yay!`);\n```\n\n* [.untilSettledOrTimedOut(executor, timeoutExecutor, timeout)](#module_timeable-promise.untilSettledOrTimedOut) ⇒ \u003ccode\u003ePromise.\u0026lt;\\*\u0026gt;\u003c/code\u003e\n    * [~executor](#module_timeable-promise.untilSettledOrTimedOut..executor) : \u003ccode\u003efunction\u003c/code\u003e\n    * [~timeoutExecutor](#module_timeable-promise.untilSettledOrTimedOut..timeoutExecutor) : \u003ccode\u003efunction\u003c/code\u003e\n\n\u003ca name=\"module_timeable-promise.untilSettledOrTimedOut..executor\"\u003e\u003c/a\u003e\n\n#### untilSettledOrTimedOut~executor : \u003ccode\u003efunction\u003c/code\u003e\nExecutor function that is executed immediately by the Promise implementation.\n\n**Kind**: inner typedef of [\u003ccode\u003euntilSettledOrTimedOut\u003c/code\u003e](#module_timeable-promise.untilSettledOrTimedOut)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| resolve | \u003ccode\u003efunction\u003c/code\u003e | Resolve the promise. |\n| reject | \u003ccode\u003efunction\u003c/code\u003e | Reject the promise. |\n| pending | \u003ccode\u003efunction\u003c/code\u003e | True if Promise is not timed out, otherwise false. |\n\n**Example**  \n```js\nconst executor = (resolve, reject, pending) =\u003e {\n  // Do something promising here...\n  if (pending()) {\n    try {\n      // Do something more promising here...\n      resolve(true);\n    } catch (ex) {\n      reject(false);\n    }\n  }\n};\n```\n\u003ca name=\"module_timeable-promise.untilSettledOrTimedOut..timeoutExecutor\"\u003e\u003c/a\u003e\n\n#### untilSettledOrTimedOut~timeoutExecutor : \u003ccode\u003efunction\u003c/code\u003e\nTimeout executor function that is executed when timeout is reached.\n\n**Kind**: inner typedef of [\u003ccode\u003euntilSettledOrTimedOut\u003c/code\u003e](#module_timeable-promise.untilSettledOrTimedOut)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| resolve | \u003ccode\u003efunction\u003c/code\u003e | Resolve the promise. |\n| reject | \u003ccode\u003efunction\u003c/code\u003e | Reject the promise. |\n\n**Example**  \n```js\nconst timeoutExecutor = (resolve, reject) =\u003e {\n  try {\n    resolve(true);\n  } catch (ex) {\n    reject(false);\n  }\n};\n```\n\u003ca name=\"module_timeable-promise.waitFor\"\u003e\u003c/a\u003e\n\n### timeable-promise.waitFor(predicate, timeout, [interval]) ⇒ \u003ccode\u003ePromise.\u0026lt;void\u0026gt;\u003c/code\u003e\nProvide waiting support on given `predicate`.\n\n**Kind**: static method of [\u003ccode\u003etimeable-promise\u003c/code\u003e](#module_timeable-promise)  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| predicate | \u003ccode\u003efunction\u003c/code\u003e |  | Predicate function. |\n| timeout | \u003ccode\u003enumber\u003c/code\u003e |  | Timeout. |\n| [interval] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e1000\u003c/code\u003e | Check interval. |\n\n**Example**  \n```js\nconst { waitFor } = require('timeable-promise');\n// Long process running...\nlet inflight = true\nconst predicate = () =\u003e !inflight;\nconst timeout = 5000;\nsetTimeout(() =\u003e {\n  // Long process done.\n  inflight = false;\n}, 1000);\nconsole.time('waitFor');\nawait waitFor(predicate, timeout);\nconsole.timeEnd('waitFor');\n```\n\nDevelopment Dependencies\n-\nYou will need to install [Node.js](https://bit.ly/2SMCGXK) as a local\ndevelopment dependency. The `npm` package manager comes bundled with all\nrecent releases of `Node.js`. You can also use [yarn](https://bit.ly/3nmWS1K)\nas a package manager.\n\n`yarn` or `npm install` will attempt to resolve any `npm` module dependencies\nthat have been declared in the project’s `package.json` file, installing them\ninto the `node_modules` folder.\n\n```bash\n$ yarn\n# or\n$ npm install\n```\n\nRun Benchmark, Leak, Lint, and Unit Tests\n-\nTo make sure we did not break anything, let's run all the tests:\n\n```bash\n$ yarn test\n# or\n$ npm run test:lint; npm run test:unit; npm run test:bench; npm run test:leak\n```\n\nRun benchmark tests only:\n\n```bash\n$ yarn test:bench\n# or\n$ npm run test:bench\n```\n\nRun leak tests only:\n\n```bash\n$ yarn test:leak\n# or\n$ npm run test:leak\n```\n\nRun lint tests only:\n\n```bash\n$ yarn test:lint\n# or\n$ npm run test:lint\n```\n\nRun unit tests only:\n\n```bash\n$ yarn test:unit\n# or\n$ npm run test:unit\n```\n\nContributing\n-\nIf you would like to contribute code to Timeable Promise repository you can do so\nthrough GitHub by forking the repository and sending a pull request.\n\nIf you do not agree to [Contribution Agreement](CONTRIBUTING.md), do not\ncontribute any code to Timeable Promise repository.\n\nWhen submitting code, please make every effort to follow existing conventions\nand style in order to keep the code as readable as possible. Please also include\nappropriate test cases.\n\nThat's it! Thank you for your contribution!\n\nLicense\n-\nCopyright (c) 2018 - 2023 Richard Huang.\n\nThis module is free software, licensed under: [GNU Affero General Public License (AGPL-3.0)](https://bit.ly/2yi7gyO).\n\nDocumentation and other similar content are provided under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://bit.ly/2SMCRlS).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickypc%2Ftimeable-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickypc%2Ftimeable-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickypc%2Ftimeable-promise/lists"}