{"id":15586694,"url":"https://github.com/innei/next-async","last_synced_at":"2026-01-07T21:38:59.803Z","repository":{"id":103747629,"uuid":"556824448","full_name":"Innei/next-async","owner":"Innei","description":"A simple implementation of koa middleware.","archived":false,"fork":false,"pushed_at":"2023-10-18T08:06:53.000Z","size":559,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-03T23:49:04.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Innei.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","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":"2022-10-24T15:27:03.000Z","updated_at":"2023-09-06T02:29:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"baff1d85-3b0c-4e95-b106-8ca7ceb0e698","html_url":"https://github.com/Innei/next-async","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Innei%2Fnext-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Innei%2Fnext-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Innei%2Fnext-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Innei%2Fnext-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Innei","download_url":"https://codeload.github.com/Innei/next-async/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246162147,"owners_count":20733357,"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-02T21:41:03.686Z","updated_at":"2026-01-07T21:38:59.753Z","avatar_url":"https://github.com/Innei.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next Async\n\nA simple implementation of koa middleware.\n\n```ts\nimport { Co } from '@innei/next-async'\n\nconst co = new Co()\nco.use(someMiddlewares)\nawait co.start()\n```\n\n## Usage\n\n**Using middleware**\n\n```ts\nconst middleware = function (args) {\n  this.next()\n}\n\nco.use(middleware)\n```\n\n**Pass context to `Co`**\n\n\n```ts\nconst co = new Co({ data: [] })\nco.use(\n  function () {\n    this.data.push(1)\n    this.next()\n  },\n  function () {\n    console.log(this.data) // [1]\n\n    this.next()\n    console.log(this.data) // [1, 2]\n  },\n  function () {\n    this.data.push(2)\n  },\n).start()\n```\n\n**Use async runner and await next runner done then back**\n\n```ts\nconst co = new Co({ data: [] })\nawait co\n  .use(\n    function () {\n      this.data.push(1)\n      this.next()\n    },\n    async function () {\n      console.log(this.data) // [1]\n\n      await this.next()\n      console.log(this.data) // [1, 2]\n    },\n    async function () {\n      await 1\n      this.data.push(2)\n    },\n  )\n  .start()\n```\n\n**Abort action in flow**\n\n```ts\nconst co = new Co({ data: [] })\nco.use(\n  function () {\n    this.data.push(1)\n    this.next()\n  },\n  function () {\n    this.abort()\n  },\n  function () {\n    this.data.push(2) // will do not run\n  },\n).start()\n```\n\n## Options\n\n```ts\nconst co = new Co(ctx, options)\n```\n\n| Key             | Type    | Default | Description                                       |\n| --------------- | ------- | ------- | ------------------------------------------------- |\n| automaticNext   | boolean | false   | Always run next action when this action returned. |\n| catchAbortError | boolean | true    | Catch CoAbortError or not.                        |\n\n## License\n\n2022 © Innei, Released under the MIT License.\n\n\u003e [Personal Website](https://innei.ren/) · GitHub [@Innei](https://github.com/innei/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finnei%2Fnext-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finnei%2Fnext-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finnei%2Fnext-async/lists"}