{"id":18338695,"url":"https://github.com/tableflip/piggybacker","last_synced_at":"2025-04-09T20:35:46.016Z","repository":{"id":57324083,"uuid":"128264490","full_name":"tableflip/piggybacker","owner":"tableflip","description":"Async keyed job runner, piggyback on results from running jobs with the same key","archived":false,"fork":false,"pushed_at":"2018-04-06T08:49:10.000Z","size":196,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-21T12:36:47.387Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tableflip.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-04-05T21:08:22.000Z","updated_at":"2020-10-12T10:59:32.000Z","dependencies_parsed_at":"2022-09-09T09:21:53.865Z","dependency_job_id":null,"html_url":"https://github.com/tableflip/piggybacker","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/tableflip%2Fpiggybacker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpiggybacker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpiggybacker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpiggybacker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tableflip","download_url":"https://codeload.github.com/tableflip/piggybacker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248108333,"owners_count":21049116,"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-11-05T20:14:53.900Z","updated_at":"2025-04-09T20:35:45.984Z","avatar_url":"https://github.com/tableflip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# piggybacker\n\n[![Build Status](https://travis-ci.org/tableflip/piggybacker.svg?branch=master)](https://travis-ci.org/tableflip/piggybacker) [![dependencies Status](https://david-dm.org/tableflip/piggybacker/status.svg)](https://david-dm.org/tableflip/piggybacker) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n\u003e Async keyed job runner, piggyback on results from running jobs with the same key\n\n## Usage\n\n```js\nimport { piggyback } from 'piggybacker'\n\nasync function fetchJSON (url) {\n  const res = await window.fetch(url)\n  return res.json()\n}\n\nconst piggyFetchJSON = piggyback(\n  fetchJSON,\n  // Given the args that will be passed to fetchJSON, generate a key so that if\n  // a second call is made while the first is in flight then the second will\n  // ALSO receive the results of the first, instead of having to make a\n  // separate request.\n  function getKey (url) {\n    return url\n  }\n)\n\nconst results = await Promise.all([\n  // Multiple calls to piggyFetchJSON with the same URL _while_ a request is in\n  // progress will not send another request! Instead they'll wait on the results\n  // of the first.\n  piggyFetchJSON('https://example.org/data.json'),\n  piggyFetchJSON('https://example.org/data.json'),\n  piggyFetchJSON('https://example.org/data.json')\n])\n\n// fetchJSON called only ONCE!\n```\n\n## API\n\n### `piggyback(fn, getKey)`\n\nCreate a new function that'll call `fn` and piggyback on the results if called again.\n\n* `fn` - the function to piggyback on\n* `getKey` - a function called before each call to `fn` that generates a key for the call. Two or more calls with the same key will be piggybacked\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/tableflip/piggybacker/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE) © Alan Shaw\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Fpiggybacker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftableflip%2Fpiggybacker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Fpiggybacker/lists"}