{"id":14989641,"url":"https://github.com/cristianbote/koa-tracks","last_synced_at":"2025-04-12T01:41:13.107Z","repository":{"id":57159218,"uuid":"164517148","full_name":"cristianbote/koa-tracks","owner":"cristianbote","description":"Koa middleware that runs multiple middleware at the same time, in parallel","archived":false,"fork":false,"pushed_at":"2019-01-09T10:23:26.000Z","size":47,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T21:21:58.813Z","etag":null,"topics":["koa","koajs","middleware","nodejs"],"latest_commit_sha":null,"homepage":"","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/cristianbote.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}},"created_at":"2019-01-08T00:01:28.000Z","updated_at":"2022-03-06T03:53:46.000Z","dependencies_parsed_at":"2022-09-07T20:11:44.293Z","dependency_job_id":null,"html_url":"https://github.com/cristianbote/koa-tracks","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianbote%2Fkoa-tracks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianbote%2Fkoa-tracks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianbote%2Fkoa-tracks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianbote%2Fkoa-tracks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cristianbote","download_url":"https://codeload.github.com/cristianbote/koa-tracks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248370661,"owners_count":21092854,"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":["koa","koajs","middleware","nodejs"],"created_at":"2024-09-24T14:18:41.594Z","updated_at":"2025-04-12T01:41:13.089Z","avatar_url":"https://github.com/cristianbote.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"koa-tracks\n===\nKoa middleware that runs multiple middleware at the same time - in parallel. Just like people are running tracks... in parallel.\n\n[![npm version](https://badge.fury.io/js/koa-tracks.svg?bust)](https://badge.fury.io/js/koa-tracks)\n[![codecov.io Code Coverage](https://img.shields.io/codecov/c/github/cristianbote/koa-tracks.svg?maxAge=2592000)](https://codecov.io/github/cristianbote/koa-tracks?branch=master)\n[![Build Status](https://travis-ci.org/cristianbote/koa-tracks.svg?branch=master)](https://travis-ci.org/cristianbote/koa-tracks)\n\n# Install\n```sh\nnpm install --save koa-tracks\n```\n\n# Usage\nThe `koa-tracks` API is rather simple. The package returns a function that needs to be called with your middleware functions, to be executed in parallel.\n\n## API\n`tracks(...entries)`\n* `entries` List of middleware functions to be executed\n\n## Example\n```js\nconst Koa = require(\"koa\");\nconst tracks = require(\"koa-tracks\");\n\nconst app = new Koa();\n\napp.use(tracks(\n    // Simple, common function that has no dependency on the results\n    ctx =\u003e ctx.state.foo = {},\n\n    // A middleware that calls a services and defines an\n    // entry on the state object\n    async ctx =\u003e {\n        // Fetch to a service\n        const data = await fetch(\"/path/to/service\");\n        ctx.state.data = data;\n    },\n\n    // Another middleware that needs to call another\n    // service and define some data\n    async ctx =\u003e {\n        // Fetch to another service\n        const data = await fetch(\"/another/path/to/service\");\n        ctx.state.anotherEntry = data;\n    }\n));\n\n// Start your server\napp.listen(8080);\n```\n\nAll of them are going to be executed in parallel. That means you're saving time as all of them are doing a request at the same time.\n\n# Things you should be aware of\n## Errors\nUnder the hood `koa-tracks` simply does a `Promise.all` with the filtered entries. So, you need to properly handle a middleware when it errors. If not, the `Promise.all` call will be rejected.\n\n# License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristianbote%2Fkoa-tracks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcristianbote%2Fkoa-tracks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristianbote%2Fkoa-tracks/lists"}