{"id":31156039,"url":"https://github.com/lvchengbin/sequence","last_synced_at":"2026-02-17T14:34:36.448Z","repository":{"id":28519454,"uuid":"117629109","full_name":"LvChengbin/sequence","owner":"LvChengbin","description":" To execute and manage asynchronous functions in sequence and controlling each step and their status for both nodejs and browsers.","archived":false,"fork":false,"pushed_at":"2022-12-06T14:37:30.000Z","size":984,"stargazers_count":4,"open_issues_count":15,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-20T06:37:38.286Z","etag":null,"topics":["async","asynchronous","callback","interval","promise","sequence"],"latest_commit_sha":null,"homepage":"","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/LvChengbin.png","metadata":{"files":{"readme":"README.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}},"created_at":"2018-01-16T03:58:47.000Z","updated_at":"2019-09-06T12:03:08.000Z","dependencies_parsed_at":"2023-01-14T08:58:44.750Z","dependency_job_id":null,"html_url":"https://github.com/LvChengbin/sequence","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LvChengbin/sequence","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fsequence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fsequence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fsequence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fsequence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LvChengbin","download_url":"https://codeload.github.com/LvChengbin/sequence/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fsequence/sbom","scorecard":{"id":87016,"data":{"date":"2025-08-11","repo":{"name":"github.com/LvChengbin/sequence","commit":"2b627d8d3d48668d5c70966896560ab82dde7df5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"75 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m","Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq","Warn: Project is vulnerable to: GHSA-pc5p-h8pf-mvwp","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c","Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-593f-38f6-jp5m","Warn: Project is vulnerable to: GHSA-x2rg-q646-7m2v","Warn: Project is vulnerable to: GHSA-jgmv-j7ww-jx2x","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4","Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g","Warn: Project is vulnerable to: GHSA-mqr2-w7wj-jjgr","Warn: Project is vulnerable to: GHSA-49j4-86m8-q2jw","Warn: Project is vulnerable to: GHSA-fpw7-j2hg-69v5","Warn: Project is vulnerable to: GHSA-4rch-2fh8-94vw","Warn: Project is vulnerable to: GHSA-pmh2-wpjm-fj45","Warn: Project is vulnerable to: GHSA-x77j-w7wf-fjmw","Warn: Project is vulnerable to: GHSA-6fx8-h7jm-663j","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3","Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj","Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4","Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq","Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-29xr-v42j-r956","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5","Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-15T07:08:22.911Z","repository_id":28519454,"created_at":"2025-08-15T07:08:22.911Z","updated_at":"2025-08-15T07:08:22.911Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275830171,"owners_count":25536280,"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","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","asynchronous","callback","interval","promise","sequence"],"created_at":"2025-09-18T20:50:55.227Z","updated_at":"2025-09-18T20:50:56.283Z","avatar_url":"https://github.com/LvChengbin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sequence\n\nTo execute and manage asynchronous functions in sequence.\n\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [Start](#start)\n* [Usage](#usage)\n* [Something About Steps.](#something-about-steps)\n* [API](#api)\n    * [Sequence( steps, options = {} )](#sequence-steps-options---)\n    * [Sequence.prototype.append( steps )](#sequenceprototypeappend-steps-)\n    * [Sequence.prototype.clear()](#sequenceprototypeclear)\n    * [Sequence.prototype.next()](#sequenceprototypenext)\n    * [Sequence.prototype.go( index )](#sequenceprototypego-index-)\n    * [Sequence.prototype.run()](#sequenceprototyperun)\n    * [Sequence.prototype.stop()](#sequenceprototypestop)\n    * [Sequence.prototype.suspend( duration = 1000 )](#sequenceprototypesuspend-duration--1000-)\n    * [Sequence.all( steps[, interval = 0, callback ] )](#sequenceall-steps-interval--0-callback--)\n    * [Sequence.chain( steps[, interval = 0, callback ] )](#sequencechain-steps-interval--0-callback--)\n    * [Sequence.any( steps[, interval = 0, callback ] )](#sequenceany-steps-interval--0-callback--)\n    * [Sequence.Error](#sequenceerror)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## Start\n\nTo install the package with `npm`.\n\n```bash\n$ npm i @lvchengbin/sequence --save\n```\nWe provide another version which is using the native `Promise` and other `ES6` features, and you can intall it with the `@next` tag:\n```bash\n$ npm i @lvchengbin/sequence@next --save\n```\n\nThen you can use it in nodejs code.\n```js\nconst Sequence = require( '@lvchengbin/sequence' );\n```\nIf you want to use the package as an ES6 module, you can import it like this:\n```js\nimport Sequence from '@lvchengbin/sequence';\n```\nWe also provide files for using in browsers with `\u003cscript\u003e` tag, you can get it here [sequence.js](https://raw.githubusercontent.com/LvChengbin/sequence/master/dist/sequence.js), and if you want to use it in browsers not supporting ES6 syntax, please use [sequence.bc.js](https://raw.githubusercontent.com/LvChengbin/sequence/master/dist/sequence.bc.js).\n\n## Usage\n\nTo create a simple sequence with `new Sequence`:\n\n```js\nimport Sequence from '@lvchengbin/sequence';\n\nconst steps = [\n    () =\u003e Promise.resolve(),\n    () =\u003e Promise.reject(),\n    () =\u003e true\n];\n\nconst sequence = new Sequence( steps, { interval : 1000 } );\n\nsequence.on( 'success', ( data, index ) =\u003e {\n    // execute when each step in sequence succeed\n} ); \n\nsequence.on( 'failed', ( data, index ) =\u003e {\n    this.go( index - 1 );\n    // execute when each step in sequence failed\n} );\n\nsequence.on( 'end', () =\u003e {\n    // execute after finishing all steps in the sequence\n} );\n```\n\nIn the code above, the functions in `steps` will execute one by one, no metter if one of them is succeed or failed, and you can get information and status by listening events `success`, `failed` and `end`.\n\nOr you can create a sequence without auto running, and to execute each step by calling the `next` method:\n\n```js\nconst sequence = new Sequence( steps, { autorun : false } );\n\nconst result = await sequence.next();\n\nif( result.status === Sequence.SUCCEEDED ) {\n    sequence.next();\n}\n```\n\nAnd you can easily create a sequence, which will execute like `Promise.all`, with `Sequence.all`:\n\n```js\nSequence.all( steps ).then( results =\u003e {\n    // some code...\n} ).catch( e =\u003e {\n    console.error( e );\n} );\n```\n\nA method `Sequence.chain` is provided for running a sequence by ignoring the result (succeeded or failed) of each step:\n\n```js\nSequence.chain( steps ).then( results =\u003e {\n    // some code...\n} );\n```\n\nFor example, if you want to send a request after user click a button, but you need to make all requests be sent one by one if the user clicked the button multiple times:\n\n```js\nconst sequence = new Sequence();\n\nsequence.on( 'failed', function() {\n    alert( 'Something error happened' );\n    this.stop();\n} );\n\nconst button = document.querySelector( '#button' );\n\nbutton.addEventListener( 'click', () =\u003e {\n    sequence.append( () =\u003e {\n        return request( 'the url' );\n    } );\n} );\n```\n\n## Something About Steps.\n\nEach step in sequence should be a function, and generally, it should return a Promise object. If the return value of one step function is not a Promise object, the return value will be converted to a Promise object with `Promise.resolve( {the return value} )`. Each step function in the sequence will be executed after its previous step function finished (no matter the Promise object is resolved or rejected).\n\nThere are three arguments will be passed to the step function, like this:\n\n```js\nconst step = ( result, index, results ) {\n    if( result.status === Sequence.SUCCEEDED ) {\n        console.log( result.value );\n        // some code...\n    } else {\n        console.log( result.reason );\n    }\n}\n```\n\n - **result** : the result of the previous step, the structure of the result is:\n\n    ```js\n    // result of a successful step\n    {\n        status : Sequence.SUCCEEDED,\n        index : 1,\n        value : 'some value here',\n        time : 1516339895559\n    }\n    // result of a failed step\n    {\n        status : Sequence.FAILED,\n        index : 2,\n        reason : 'some reason here',\n        time : 1516339895559\n    }\n    ```\n\n    - status : the status of the result, it can be `Sequence.SUCCEEDED` or `Sequence.FAILED`.\n    - index : the position of the step in the sequence.\n    - value : the value of the resolved promise of the step.\n    - reason : the failed reason of the rejecte promise of the step.\n    - time : the time that the step finished.\n\n- **index** : the order of the step in sequence\n\n- **results** : the full result list of all finished steps.\n\n## API\n\n### Sequence( steps, options = {} )\n\n**Parameters**\n\n- steps `Function` | `Iterable`\n\n    The steps that you want to add to the sequence, each step must be a `Function` and should return a Promise object, if the return value of a step is not a Promise object, it will be converted to a resolved Promise instance as its value is the return value.\n\n- options `Object`\n\n    Options for the sequence, this is the list of options which are supported:\n\n    - autorun `Boolean` - Default : true\n\n        Denoting if the sequence should be run automatically after creating.\n\n    - interval `Number` - Default : 0\n\n        The interval between each step, the unit is `ms`.\n\n**Properties of Sequence instance**\n\n - running : denoting if the sequence is running.\n - suspended : denoting if the sequence is suspended.\n - busy : denoting if there is a step in the sequence is in process.\n - interval : the interval between executing two steps, you can change is as you want.\n - steps : all steps of the sequence.\n - index : the order of the step which will be executed next time.\n - results : an array for all results of each step.\n\n**Example**\n\n```js\nnew Sequence( [\n    () =\u003e Promise.resolve(),\n    () =\u003e {\n        // this function will execute 1s after the previous one finished.\n        return true;\n    }\n], {\n    autorun : true,\n    interval : 1000\n} )\n```\n\n### Sequence.prototype.append( steps )\n\nTo append new steps into the sequence.\n\n**Parameters**\n\n - steps `Function` | `Iterable`\n    \n    The steps that you want to append to the sequence, each step must be a `Function` and should return a Promise object, if the return value of a step is not a Promise object, it will be converted to a resolved Promise object as its value is the return value.\n    \n**Example**\n\n```js\nconst sequence = new Sequence();\n\nsequence.append( () =\u003e {\n    return request( url );\n} );\n```\n\n### Sequence.prototype.clear()\n\nTo remove all steps in the sequence no matter if the steps have executed.\n\n### Sequence.prototype.next()\n\nTo run the next step in ths sequence if the sequence is not running. It cannot use while the sequence is running.\n\nIf there is a step in process while calling this method, the sequence will not go to the next step.\n\n**Return value**\n\nIf the method execute successfully, a resolved Promise object of the step will be returned, otherwise a rejected one will be returned.\n\nBut in different situations, there would be some different result:\n\n - When this method is called, if there is a step in process, the method will return the Promise object of the running step.\n - When this method is called while the sequence is running, a rejected Promise instance will be returned, and the reason the the instance will be a `Sequence.Error` instance with `errno` is `2`.\n - When this method is called while the sequence already reached the end, a rejected Promise instance will be returned, and the reason the the instance will be a `Sequence.Error` instance with `errno` is `1`.\n\n**Example**\n\n```js\nconst sequence = new Sequence( steps, { autorun : false } );\n\nsequence.next().then( result =\u003e {\n} );\n```\n\n### Sequence.prototype.go( index )\n\nTo jump to a specified This method just set the cursor of the sequence to the previous one and it will not \n\n**Parameters**\n\n - index `Integer`\n\n The index of step to jump to.\n\n**Example**\n\n```js\nconst sequence = new Sequence( steps );\n\nsequence.on( 'failed', ( data, index ) =\u003e {\n    sequence.go( index - 1 ); // will re-execute this step.\n} );\n```\nNotice that, by listening to the `failed` event, cannot pend the sequence, so you cannot do some async things before you decide if you need to jump to one step.But maybe you can use it with `stop` method. For example:\n\n```js\nconst sequence = new Sequence( steps );\n\nsequence.on( 'failed', ( data, index ) =\u003e {\n    sequence.stop();\n\n    setTimeout( () =\u003e {\n        sequence.go( index - 1 );\n        sequence.run();\n    }, 1000 )\n} );\n```\n\n### Sequence.prototype.run()\n\nTo run the sequence if it is not running.\n\n### Sequence.prototype.stop()\n\nTo stop the sequence if it is running\n\n### Sequence.prototype.suspend( duration = 1000 )\n\nTo suspend the sequence with specfiying a time then the sequence will be paused for a while and continue executing after the duration you set. During the time the sequence suspended, the sequence is still running.\n\n**Parameters**\n\n - duration `Integer` - Default : 1000\n\n    The duration you want to suspended the sequence, its unit is `ms`.\n\n**Example**\n\n```js\n\nconst sequence = new Sequence( steps );\n\nsequence.on( 'success', ( data, index ) =\u003e {\n    if( index % 10 ) {\n        sequence.suspend( 5000 );\n    }\n} );\n```\n\n### Sequence.all( steps[, interval = 0, callback ] )\n\nTo run all steps in a sequence, the sequence will return a resolved Promise instance after all steps finished. If one of the steps failed, the function will return a rejected Promise, and if the steps is empty, the function will return a resolved Promise.\n\nThe param `interval` is used for denoting the interval between each two steps.\n\nThe param `callback` will be executed after creating the instance of `Sequence`, so you can control the instance of `Sequence` with this param.\n\nThe value of the resolved promise will be an `Array` filled with result of each step.\n\n```js\nSequence.all( [\n    () =\u003e Promise.resolve( 1 ),\n    () =\u003e true\n] ).then( results =\u003e {\n    // result list of the sequence\n    // some code...\n} ).catch( results =\u003e {\n    // result list of the sequence\n    // some code...\n} );\n\nSequence.all( [], sequence =\u003e {\n    sequence.on( 'success', () =\u003e {} );\n} );\n```\n\n### Sequence.chain( steps[, interval = 0, callback ] )\n\nTo run all steps in a sequence, and doesn't care about if all of the steps succeeded, a `Promise` will be returned, and its value will be a full list of the results of the sequence, and if the steps is empty, a resolved Promise will be returned directly.\n\n```js\nSequence.chain( [\n    () =\u003e Promise.resolve( 'success' ),\n    () =\u003e Promise.reject( 'failed' )\n] ).then( results =\u003e {\n    // result list of the sequence\n    // some code...\n} );\n```\n\n### Sequence.any( steps[, interval = 0, callback ] )\n\nTo run the steps in sequence until one of them succeeded and a resolved Promise object will be returned. If all the steps executed failed, a rejected Promise object will be returned, and if the steps is empty, a rejected Promise will be returned.\n\n```js\nSequence.any( [\n    () =\u003e Promise.reject(),\n    () =\u003e Promise.resolve( true ),\n    () =\u003e {\n        // this function will not execute because the previous one succeeded.\n        return true;\n    }\n] ).then( results =\u003e {\n    // result list of the sequence\n    // some code...\n} ).catch( results =\u003e {\n    // result list of the sequence\n    // some sode...\n} );\n```\n\n### Sequence.Error\n\nAn error class for sequences.\n\n```js\nconst sequence = new Sequence( [] );\n\nsequence.next().catch( e =\u003e {\n    if( e instanceof Sequence.Error ) {\n        // some code...\n    }\n} );\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flvchengbin%2Fsequence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flvchengbin%2Fsequence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flvchengbin%2Fsequence/lists"}