tableflip/piggybacker

Name: piggybacker

Owner: TABLEFLIP

Description: Async keyed job runner, piggyback on results from running jobs with the same key

Created: 2018-04-05 21:08:22.0

Updated: 2018-04-06 08:49:13.0

Pushed: 2018-04-06 08:49:10.0

Homepage: null

Size: 196

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

piggybacker

Build Status dependencies Status JavaScript Style Guide

Async keyed job runner, piggyback on results from running jobs with the same key

Usage
rt { piggyback } from 'piggybacker'

c function fetchJSON (url) {
nst res = await window.fetch(url)
turn res.json()


t piggyFetchJSON = piggyback(
tchJSON,
 Given the args that will be passed to fetchJSON, generate a key so that if
 a second call is made while the first is in flight then the second will
 ALSO receive the results of the first, instead of having to make a
 separate request.
nction getKey (url) {
return url



t results = await Promise.all([
 Multiple calls to piggyFetchJSON with the same URL _while_ a request is in
 progress will not send another request! Instead they'll wait on the results
 of the first.
ggyFetchJSON('https://example.org/data.json'),
ggyFetchJSON('https://example.org/data.json'),
ggyFetchJSON('https://example.org/data.json')


etchJSON called only ONCE!
API
piggyback(fn, getKey)

Create a new function that'll call fn and piggyback on the results if called again.

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.