{"id":25933357,"url":"https://github.com/robertwhurst/relign","last_synced_at":"2025-03-04T00:53:32.540Z","repository":{"id":49610721,"uuid":"71095212","full_name":"RobertWHurst/Relign","owner":"RobertWHurst","description":"Relign is a little utility library for processing data and tasks in concurrent or serial patterns","archived":false,"fork":false,"pushed_at":"2024-06-23T02:34:57.000Z","size":241,"stargazers_count":39,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-31T05:52:18.404Z","etag":null,"topics":["async","concurrency","javascript","parallelism","promises","tasks","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/RobertWHurst.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.txt","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},"funding":{"github":["RobertWHurst"]}},"created_at":"2016-10-17T03:04:23.000Z","updated_at":"2024-08-23T15:45:35.000Z","dependencies_parsed_at":"2023-12-19T14:56:26.397Z","dependency_job_id":"bdc58116-4a22-4dc8-8b7d-6fc4c7672ce6","html_url":"https://github.com/RobertWHurst/Relign","commit_stats":{"total_commits":64,"total_committers":4,"mean_commits":16.0,"dds":0.328125,"last_synced_commit":"82763c8ca2e6f8c8ca18cd10e4586e83c125212a"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FRelign","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FRelign/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FRelign/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FRelign/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobertWHurst","download_url":"https://codeload.github.com/RobertWHurst/Relign/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763726,"owners_count":20016162,"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":["async","concurrency","javascript","parallelism","promises","tasks","typescript"],"created_at":"2025-03-04T00:53:31.866Z","updated_at":"2025-03-04T00:53:32.529Z","avatar_url":"https://github.com/RobertWHurst.png","language":"TypeScript","funding_links":["https://github.com/sponsors/RobertWHurst"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg alt=\"Relign\" title=\"Relign\" src=\"https://github.com/RobertWHurst/relign/assets/178857/4df2a8cc-9873-49b2-b3cc-a4faa7166ff2\"\u003e\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/relign\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/relign\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/relign\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/relign\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/RobertWHurst/Relign/actions/workflows/ci.yml\"\u003e\n    \u003cimg src=\"https://github.com/RobertWHurst/Relign/actions/workflows/ci.yml/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/sponsors/RobertWHurst\"\u003e\n    \u003cimg src=\"https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%23fe8e86\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://openbase.com/js/relign?utm_source=embedded\u0026amp;utm_medium=badge\u0026amp;utm_campaign=rate-badge\"\u003e\n    \u003cimg src=\"https://badges.openbase.com/js/featured/relign.svg?token=2wanGBvFibIfrdpnvnSioqIgoC7lJt3ztNNcKsRw+Pg=\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n__If you encounter a bug please [report it][bug-report].__\n\nRelign is a little utility library for processing data and tasks in concurrent\nor serial patterns. It's heavily inspired by the wonderful library [async][async]\nwhich was widly used back in the bad old days of callback patterns popular in\nnode programs at the time. Relign is for modern TypeScript and JavaScript programs\nthat use async functions and promises. It's not just an alternative to Promise.all\nbut an advanced utility library that fills the gaps in asynchronous patterns,\nmaking them more developer-friendly and maintainable.\n\nRelign is a collection of functions that take tasks or data and process them in\nvarious ways. These functions are all designed to be simple and easy to use\nwithout confusion.\n\n## Installation\n\nRelign is published on [NPM][npm]. It can be used in any TypeScript or JavaScript\nproject, and is esm or cjs compatible.\n\n```shell\nnpm i relign\n```\n\n```ts\nimport { parallelMapLimit } from 'relign';\n\nconst urlsToFetch: string[] = [\n  'https://coolsite.com/path/one',\n  'https://coolsite.com/path/two',\n  'https://coolsite.com/path/three',\n  //...\n  'https://coolsite.com/path/oneThousand',\n]\n\nconst resultJson = await parallelMapLimit(urlsToFetch, async url =\u003e {\n  const response = await fetch(url);\n  return response.json();\n}, 10);\n```\n\n## A Note on Execution\n\nOne of the main things that make relign special is how it handles data or tasks.\n\nRelign will happily accept any value as a task. If the value is a function it\nwill be executed. If the value is a promise it will be awaited. If the value is\na function that returns a promise, the promise will be awaited. If the value is\nanything else it will be returned as is. This means that you can pass a mix of\nfunctions, promises, and values to any relign function accepting tasks and it\nwill do the right thing.\n\nItem functions work in a similar way, but instead these\nfunctions take a worker function that is called for each item in the collection.\nThis function is executed in the same way as tasks. That means if the worker\nreturns a promise, the promise will be awaited. If the worker returns a value\nthat value will be returned as is.\n\n## Function Index\n\n- [parallel](#parallel)\n- [parallelLimit](#parallel-limit)\n- [series](#series)\n- [auto](#auto)\n- [parallelMap](#parallel-map)\n- [parallelMapLimit](#parallel-map-limit)\n- [seriesMap](#series-map)\n- [parallelFilter](#parallel-filter)\n- [parallelFilterLimit](#parallel-filter-limit)\n- [seriesFilter](#series-filter)\n- [parallelFind](#parallel-find)\n- [parallelFindLimit](#parallel-find-limit)\n- [seriesFind](#series-find)\n- [parallelFlatMap](#parallel-flat-map)\n- [parallelFlatMapLimit](#parallel-flat-map-limit)\n- [seriesFlatMap](#series-flat-map)\n- [seriesReduce](#series-reduce)\n- [nextTick](#next-tick)\n- [setTimeout](#set-timeout)\n- [setInterval](#set-interval)\n- [cbToPromise](#callback-to-promise)\n- [exec](#execute)\n\n## Parallel\n\nThe `parallel` function takes a collection of tasks and executes them concurrently.\nIt returns a promise that resolves to an array of the results of each task. It\nwill happily accept an array or object of tasks. Tasks can be functions, promises,\nfunctions that return a promise, or any other value.\n\n__With an Array__\n\n```ts\nimport { parallel } from 'relign';\n\nconst results = await parallel([\n  1,\n  Promise.resolve(2),\n  async () =\u003e 3,\n  async () =\u003e Promise.resolve(4),\n])\n\nconsole.log(results); // [1, 2, 3, 4]\n```\n\n__With an Object__\n\n```ts\nimport { parallel } from 'relign';\n\nconst results = await parallel({\n  one: 1,\n  two: Promise.resolve(2),\n  three: async () =\u003e 3,\n  four: async () =\u003e Promise.resolve(4),\n})\n\nconsole.log(results); // { one: 1, two: 2, three: 3, four: 4 }\n```\n\n## Parallel Limit\n\nThe `parallelLimit` function takes a collection of tasks and executes them\nconcurrently with a limit on the number of tasks that can be executed at once.\nIt returns a promise that resolves to an array of the results of each task. It\nwill happily accept an array or object of tasks. Tasks can be functions, promises,\nfunctions that return a promise, or any other value.\n\n__With an Array__\n\n```ts\nimport { parallelLimit } from 'relign';\n\nconst results = await parallelLimit([\n  1,\n  Promise.resolve(2),\n  async () =\u003e 3,\n  async () =\u003e Promise.resolve(4),\n], 2)\n\nconsole.log(results); // [1, 2, 3, 4]\n```\n\n__With an Object__\n\n```ts\nimport { parallelLimit } from 'relign';\n\nconst results = await parallelLimit({\n  one: 1,\n  two: Promise.resolve(2),\n  three: async () =\u003e 3,\n  four: async () =\u003e Promise.resolve(4),\n}, 2)\n\nconsole.log(results); // { one: 1, two: 2, three: 3, four: 4 }\n```\n\n## Series\n\nThe `series` function takes a collection of tasks and executes them in series.\nIt returns a promise that resolves to an array of the results of each task. It\nwill happily accept an array or object of tasks. Tasks can be functions, promises,\nfunctions that return a promise, or any other value.\n\n__With an Array__\n\n```ts\nimport { series } from 'relign';\n\nconst results = await series([\n  1,\n  Promise.resolve(2),\n  async () =\u003e 3,\n  async () =\u003e Promise.resolve(4),\n])\n\nconsole.log(results); // [1, 2, 3, 4]\n```\n\n__With an Object__\n\n```ts\nimport { series } from 'relign';\n\nconst results = await series({\n  one: 1,\n  two: Promise.resolve(2),\n  three: async () =\u003e 3,\n  four: async () =\u003e Promise.resolve(4),\n})\n\nconsole.log(results); // { one: 1, two: 2, three: 3, four: 4 }\n```\n\n## Auto\n\nThe `auto` function is great when you want tasks to be executed in a specific\norder based on dependencies on one another, but still want to run non interdependent\ntasks concurrently. It takes an object with a key for each task and a array value\nof dependencies and a task. It returns a promise that resolves to an object with\nthe results of each task. Tasks can be functions, promises, functions that return\npromises, or any other value.\n\n```ts\nimport { auto } from 'relign';\n\nconst results = await auto({\n  one: [1],\n  two: [Promise.resolve(2)],\n  three: ['one', 'two', async ({ one, two }) =\u003e one + two],\n  four: ['two', async ({ two }) =\u003e two * 2],\n})\n\nconsole.log(results); // { one: 1, two: 2, three: 3, four: 4 }\n```\n\n## Parallel Map\n\nThe `parallelMap` function takes a collection of items and a map function. It\nwill then concurrently process each item in the collection with the map function.\nNote that the map function can return a promise or any other value. If a promise\nis returned, the result of the promise will be used as the value for the item in\nthe results array. If any other value is returned, that value will be used as is.\n\n__With an Array__\n\n```ts\nimport { parallelMap } from 'relign';\n\nconst results = await parallelMap([1, 2, 3, 4], async (item) =\u003e {\n  return item * 2;\n})\n\nconsole.log(results); // [2, 4, 6, 8]\n```\n\n__With an Object__\n\n```ts\nimport { parallelMap } from 'relign';\n\nconst results = await parallelMap({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item * 2;\n})\n\nconsole.log(results); // { one: 2, two: 4, three: 6, four: 8 }\n```\n\n## Parallel Map Limit\n\nThe `parallelMapLimit` function takes a collection of items, a map function, and\na limit. It will then concurrently process each item in the collection with the\nmap function with a limit on the number of items that can be processed at once.\nNote that the map function can return a promise or any other value. If a promise\nis returned, the result of the promise will be used as the value for the item in\nthe results array. If any other value is returned, that value will be used as is.\n\n__With an Array__\n\n```ts\nimport { parallelMapLimit } from 'relign';\n\nconst results = await parallelMapLimit([1, 2, 3, 4], async (item) =\u003e {\n  return item * 2;\n}, 2)\n\nconsole.log(results); // [2, 4, 6, 8]\n```\n\n__With an Object__\n\n```ts\nimport { parallelMapLimit } from 'relign';\n\nconst results = await parallelMapLimit({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item * 2;\n}, 2)\n\nconsole.log(results); // { one: 2, two: 4, three: 6, four: 8 }\n```\n\n## Series Map\n\nThe `seriesMap` function takes a collection of items and a map function. It\nwill then process each item in the collection with the map function in series.\nNote that the map function can return a promise or any other value. If a promise\nis returned, the result of the promise will be used as the value for the item in\nthe results array. If any other value is returned, that value will be used as is.\n\n__With an Array__\n\n```ts\nimport { seriesMap } from 'relign';\n\nconst results = await seriesMap([1, 2, 3, 4], async (item) =\u003e {\n  return item * 2;\n})\n\nconsole.log(results); // [2, 4, 6, 8]\n```\n\n__With an Object__\n\n```ts\nimport { seriesMap } from 'relign';\n\nconst results = await seriesMap({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item * 2;\n})\n\nconsole.log(results); // { one: 2, two: 4, three: 6, four: 8 }\n```\n\n## Parallel Filter\n\nThe `parallelFilter` function takes a collection of items and a filter function.\nIt will then concurrently process each item in the collection with the filter\nfunction. Note that the filter function can return a promise that resolves to a\nboolean or a boolean. The boolean will be used to determine if the item should\nbe included in the results.\n\n__With an Array__\n\n```ts\nimport { parallelFilter } from 'relign';\n\nconst results = await parallelFilter([1, 2, 3, 4], async (item) =\u003e {\n  return item % 2 === 0;\n})\n\nconsole.log(results); // [2, 4]\n```\n\n__With an Object__\n\n```ts\nimport { parallelFilter } from 'relign';\n\nconst results = await parallelFilter({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item % 2 === 0;\n})\n\nconsole.log(results); // { two: 2, four: 4 }\n```\n\n## Parallel Filter Limit\n\nThe `parallelFilterLimit` function takes a collection of items, a filter\nfunction, and a limit. It will then concurrently process each item in the\ncollection with the filter function with a limit on the number of items that can\nbe processed at once. Note that the filter function can return a promise that\nresolves to a boolean or a boolean. The boolean will be used to determine if the\nitem should be included in the results.\n\n__With an Array__\n\n```ts\nimport { parallelFilterLimit } from 'relign';\n\nconst results = await parallelFilterLimit([1, 2, 3, 4], async (item) =\u003e {\n  return item % 2 === 0;\n}, 2)\n\nconsole.log(results); // [2, 4]\n```\n\n__With an Object__\n\n```ts\nimport { parallelFilterLimit } from 'relign';\n\nconst results = await parallelFilterLimit({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item % 2 === 0;\n}, 2)\n\nconsole.log(results); // { two: 2, four: 4 }\n```\n\n## Series Filter\n\nThe `seriesFilter` function takes a collection of items and a filter function.\nIt will then process each item in the collection with the filter function in\nseries. Note that the filter function can return a promise that resolves to a\nboolean or a boolean. The boolean will be used to determine if the item should\nbe included in the results.\n\n__With an Array__\n\n```ts\nimport { seriesFilter } from 'relign';\n\nconst results = await seriesFilter([1, 2, 3, 4], async (item) =\u003e {\n  return item % 2 === 0;\n})\n\nconsole.log(results); // [2, 4]\n```\n\n__With an Object__\n\n```ts\nimport { seriesFilter } from 'relign';\n\nconst results = await seriesFilter({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item % 2 === 0;\n})\n\nconsole.log(results); // { two: 2, four: 4 }\n```\n\n## Parallel Find\n\nThe `parallelFind` function takes a collection of items and a find function. It\nwill then concurrently execute the find function on each item in the collection\nuntil the find function returns a promise that resolves to true, or true. The\nfirst item to result in true being returned or resolved will be returned as the\nresult. If no item results in true, undefined will be returned.\n\n__With an Array__\n\n```ts\nimport { parallelFind } from 'relign';\n\nconst result = await parallelFind([1, 2, 3, 4], async (item) =\u003e {\n  return item === 3;\n})\n\nconsole.log(result); // 3\n```\n\n__With an Object__\n\n```ts\nimport { parallelFind } from 'relign';\n\nconst result = await parallelFind({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item === 3;\n})\n\nconsole.log(result); // 3\n```\n\n## Parallel Find Limit\n\nThe `parallelFindLimit` function takes a collection of items, a find function,\nand a limit. It will then concurrently execute the find function on each item in\nthe collection with a limit on the number of items that can be processed at\nonce. The find function will be executed on each item in the collection until\nthe find function returns a promise that resolves to true, or true. The first\nitem to result in true being returned or resolved will be returned as the\nresult. If no item results in true, undefined will be returned.\n\n__With an Array__\n\n```ts\nimport { parallelFindLimit } from 'relign';\n\nconst result = await parallelFindLimit([1, 2, 3, 4], async (item) =\u003e {\n  return item === 3;\n}, 2)\n\nconsole.log(result); // 3\n```\n\n__With an Object__\n\n```ts\nimport { parallelFindLimit } from 'relign';\n\nconst result = await parallelFindLimit({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item === 3;\n}, 2)\n\nconsole.log(result); // 3\n```\n\n## Series Find\n\nThe `seriesFind` function takes a collection of items and a find function. It\nwill then execute the find function on each item in the collection in series\nuntil the find function returns a promise that resolves to true, or true. The\nfirst item to result in true being returned or resolved will be returned as the\nresult. If no item results in true, undefined will be returned.\n\n__With an Array__\n\n```ts\nimport { seriesFind } from 'relign';\n\nconst result = await seriesFind([1, 2, 3, 4], async (item) =\u003e {\n  return item === 3;\n})\n\nconsole.log(result); // 3\n```\n\n__With an Object__\n\n```ts\nimport { seriesFind } from 'relign';\n\nconst result = await seriesFind({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return item === 3;\n})\n\nconsole.log(result); // 3\n```\n\n## Parallel Flat Map\n\nThe `parallelFlatMap` function takes a collection of items and a flat map function.\nIt will then concurrently execute the flat map function on each item in the\ncollection. Note that the flat map function can return a promise that resolves\nto an array or an array. The array will be flattened into the result.\n\n__With an Array__\n\n```ts\nimport { parallelFlatMap } from 'relign';\n\nconst results = await parallelFlatMap([1, 2, 3, 4], async (item) =\u003e {\n  return [item, item];\n})\n\nconsole.log(results); // [1, 1, 2, 2, 3, 3, 4, 4]\n```\n\n__With an Object__\n\n```ts\nimport { parallelFlatMap } from 'relign';\n\nconst results = await parallelFlatMap({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return [item, item];\n})\n\nconsole.log(results); // [1, 1, 2, 2, 3, 3, 4, 4]\n```\n\n## Parallel Flat Map Limit\n\nThe `parallelFlatMapLimit` function takes a collection of items, a flat map\nfunction, and a limit. It will then concurrently execute the flat map function\non each item in the collection with a limit on the number of items that can be\nprocessed at once. Note that the flat map function can return a promise that\nresolves to an array or an array. The array will be flattened into the result.\n\n__With an Array__\n\n```ts\nimport { parallelFlatMapLimit } from 'relign';\n\nconst results = await parallelFlatMapLimit([1, 2, 3, 4], async (item) =\u003e {\n  return [item, item];\n}, 2)\n\nconsole.log(results); // [1, 1, 2, 2, 3, 3, 4, 4]\n```\n\n__With an Object__\n\n```ts\nimport { parallelFlatMapLimit } from 'relign';\n\nconst results = await parallelFlatMapLimit({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return [item, item];\n}, 2)\n\nconsole.log(results); // [1, 1, 2, 2, 3, 3, 4, 4]\n```\n\n## Series Flat Map\n\nThe `seriesFlatMap` function takes a collection of items and a flat map\nfunction. It will then execute the flat map function on each item in the\ncollection in series. Note that the flat map function can return a promise that\nresolves to an array or an array. The array will be flattened into the result.\n\n__With an Array__\n\n```ts\nimport { seriesFlatMap } from 'relign';\n\nconst results = await seriesFlatMap([1, 2, 3, 4], async (item) =\u003e {\n  return [item, item];\n})\n\nconsole.log(results); // [1, 1, 2, 2, 3, 3, 4, 4]\n```\n\n__With an Object__\n\n```ts\nimport { seriesFlatMap } from 'relign';\n\nconst results = await seriesFlatMap({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (item) =\u003e {\n  return [item, item];\n})\n\nconsole.log(results); // [1, 1, 2, 2, 3, 3, 4, 4]\n```\n\n## Series Reduce\n\nThe `seriesReduce` function takes a collection of items, a reducer function,\nand an initial value. It will then execute the reducer function on each item in\nthe collection in series. The result of the reducer function can be a promise\nor any value. If the reducer function returns a promise, the result of the\npromise will be used as the memo for the next iteration, otherwise\nthe return value will be used as the memo. After all items have been processed,\nthe memo will be returned as the result.\n\n__With an Array__\n\n```ts\nimport { seriesReduce } from 'relign';\n\nconst result = await seriesReduce([1, 2, 3, 4], async (memo, item) =\u003e {\n  return memo + item;\n}, 0)\n\nconsole.log(result); // 10\n```\n\n__With an Object__\n\n```ts\nimport { seriesReduce } from 'relign';\n\nconst result = await seriesReduce({\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n}, async (memo, item) =\u003e {\n  return memo + item;\n}, 0)\n\nconsole.log(result); // 10\n```\n\n## Next Tick\n\nThe `nextTick` function returns a promise that resolves on the next tick of the\nevent loop. If used in a browser, requestAnimationFrame under the hood instead\nof node's process.nextTick.\n\n```ts\nimport { nextTick } from 'relign';\n\nawait nextTick();\n```\n\nNext tick can also take a task or value as an argument. If a task is passed,\nthe task will be executed on the next tick of the event loop and the promise\nwill resolve to the result of the task. If a value is passed, the promise will\nresolve to the value on the next tick of the event loop.\n\n```ts\nimport { nextTick } from 'relign';\n\nconst result = await nextTick(() =\u003e {\n  return 'hello world';\n});\n\nconsole.log(result); // 'hello world'\n```\n\n## Set Timeout\n\nThe `setTimeout` takes a delay and returns a promise that resolves after the\ndelay has elapsed.\n\n```ts\nimport { setTimeout } from 'relign';\n\nawait setTimeout(1000);\n```\n\nSet timeout can also take a task or value as an argument. If a task is passed,\nthe task will be executed after the delay has elapsed and the promise will\nresolve to the result of the task. If a value is passed, the promise will\nresolve to the value after the delay has elapsed.\n\n```ts\nimport { setTimeout } from 'relign';\n\nconst result = await setTimeout(1000, () =\u003e {\n  return 'hello world';\n});\n\nconsole.log(result); // 'hello world'\n```\n\n## Set Interval\n\nThe `setInterval` takes a task and a interval duration. It will call the task\nevery interval period until the task throws, or executes the resolve function\npassed to it. The promise returned by setInterval will not resolve until the\ntask throws or executes the resolve function passed to it. If the task calls\nthe resolve function and passes a value, the promise will resolve to that\nvalue.\n\n```ts\nimport { setInterval } from 'relign';\n\nlet count = 0;\n\nconst result = await setInterval(1000, (resolve) =\u003e {\n  count += 1;\n\n  if (count === 5) {\n    resolve(count);\n  }\n});\n\nconsole.log(result); // 5\n```\n\n## Callback to Promise\n\nThe `cbToPromise` function takes a function that uses the error first callback\npattern and returns a function that returns a promise. The returned function\nwill call the original function and resolve or reject the promise based on the\nerror first callback.\n\n```ts\nimport { cbToPromise } from 'relign';\n\nconst readFile = cbToPromise(fs.readFile);\n\nconst result = await readFile('./package.json', 'utf8');\n\nconsole.log(result); // package.json contents\n```\n\n## Execute\n\nThe `exec` function is the heart of relign and is used by a majority of the\nfunctions above. The execute function takes a task or value and executes it.\nIf the task is a function, it will be called and the result will be returned.\nIf the task is a promise, the promise will be awaited and the result will be\nreturned. If the task is any other value, the value will be returned.\n\n```ts\nimport { exec } from 'relign';\n\nconst result = exec(() =\u003e {\n  return 'hello world';\n});\n\nconsole.log(result); // 'hello world'\n```\n\n## Help Welcome\n\nIf you want to support this project by throwing be some coffee money It's\ngreatly appreciated.\n\n[![sponsor](https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%23fe8e86)](https://github.com/sponsors/RobertWHurst)\n\nIf your interested in providing feedback or would like to contribute please feel\nfree to do so. I recommend first [opening an issue][feature-request] expressing\nyour feedback or intent to contribute a change, from there we can consider your\nfeedback or guide your contribution efforts. Any and all help is greatly\nappreciated since this is an open source effort after all.\n\nThank you!\n\n[npm]: https://www.npmjs.com\n[async]: https://github.com/caolan/async\n[bug-report]: https://github.com/RobertWHurst/Relign/issues/new?template=bug_report.md\n[feature-request]: https://github.com/RobertWHurst/Relign/issues/new?template=feature_request.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertwhurst%2Frelign","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertwhurst%2Frelign","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertwhurst%2Frelign/lists"}