{"id":17349190,"url":"https://github.com/co2-git/sequencer","last_synced_at":"2025-07-27T11:37:01.438Z","repository":{"id":68259664,"uuid":"49229134","full_name":"co2-git/sequencer","owner":"co2-git","description":"Execute promises one after the other","archived":false,"fork":false,"pushed_at":"2016-04-23T16:32:45.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T16:23:10.374Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/co2-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2016-01-07T20:33:53.000Z","updated_at":"2016-02-10T04:42:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f05c6a2-2d56-405e-b35a-b05299397a9e","html_url":"https://github.com/co2-git/sequencer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fsequencer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fsequencer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fsequencer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fsequencer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co2-git","download_url":"https://codeload.github.com/co2-git/sequencer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245841690,"owners_count":20681184,"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-10-15T16:55:00.726Z","updated_at":"2025-03-27T11:44:18.363Z","avatar_url":"https://github.com/co2-git.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"sequencer\n===\n\nRun promises one after the other.\n\n# Install\n\n```bash\nnpm install promise-sequencer\n```\n\n# Usage\n\n```js\nimport sequencer from 'promise-sequencer';\n```\n\n# Promise\n\nIf you use standard promises, you have the method `all()` that will run a batch of promises independently from one to the other. `sequencer` will run them one by one, stopping if one in the stack fails.\n\n# Usage\n\n```js\nsequencer(\n\n  () =\u003e new Promise(resolve =\u003e resolve(1)),\n\n  () =\u003e new Promise(resolve =\u003e resolve(true))\n\n);\n```\n\nSecond promise is run only after and if first promise has resolved.\n\n# Rejections\n\nA rejection would stop the stack.\n\n```js\nsequencer(\n\n  () =\u003e new Promise((resolve, reject) =\u003e reject(new Error('Bug!'))),\n\n  () =\u003e new Promise(resolve =\u003e resolve(true))\n\n);\n```\n\nHere, the second promise is never called.\n\n# Piping promises\n\nThe output of a promise is passed down to the next promise in stack:\n\n```js\nsequencer(\n\n  () =\u003e new Promise(resolve =\u003e resolve(1)),\n\n  number =\u003e new Promise(() =\u003e {\n    console.log(number); // 1\n  })\n\n);\n```\n\nYou can also use a second argument, which is the current buffer of all outputs so far in stack.\n\n```js\nsequencer(\n\n  () =\u003e new Promise(resolve =\u003e resolve(1)),\n\n  () =\u003e new Promise(resolve =\u003e resolve(2)),\n\n  (number, results) =\u003e new Promise(resolve =\u003e {\n    console.log(number); // 2\n    console.log(results); // [1, 2]\n    resolve();\n  })\n\n);\n```\n\n# Chain\n\nsequencer returns a promise itself. The arguments of the results of all the stack.\n\n```js\nsequencer(\n\n  () =\u003e new Promise(resolve =\u003e resolve(1)),\n\n  () =\u003e new Promise(resolve =\u003e resolve(2))\n\n)\n.then(results =\u003e {\n  console.log(results); // [1, 2]\n})\n.catch(error =\u003e { /*...*/ });\n```\n\nIf you want the sequencer to return the last resolve, use `sequencer.pipe()`:\n\n```js\nsequencer.pipe(\n\n  () =\u003e new Promise(resolve =\u003e resolve(1)),\n\n  () =\u003e new Promise(resolve =\u003e resolve(2))\n\n)\n.then(result =\u003e {\n  console.log(result); // 2\n})\n```\n\n# Signature\n\nYou can declare the stack of promises as an array or as a list:\n\n```js\nsequencer(promise1, promise2); // this is correct\nsequencer([promise1, promise2]); // this is correct too\n```\n\n# Promisify\n\nsequencer comes bundled with an utility that can run node callbacks as a promise:\n\n```js\nsequencer.promisify(fs.readdir, [__dirname]).then(/*...*/);\n\n// Signature\npromisify(Function functionWithCallback, [Mixed arguments]?, {Object functionBinder}?)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fsequencer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco2-git%2Fsequencer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fsequencer/lists"}