JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2189
  • Score
    100M100P100Q123431F
  • License MIT

add AbortController support to a cache of async requests

Package Exports

  • abortable-promise-cache

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (abortable-promise-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

abortable-promise-cache

NPM version Coverage Status Build Status

Adds AbortController/AbortSignal semantics to a cache of promises. Each get from the cache can optionally take an AbortSignal object that lets that request be aborted.

Cached fill requests will be aborted and evicted from the cache if all the incoming requests for it are aborted before the promise settles.

If the fill request has already settled before all the requests for it have been aborted, it will stay in the cache.

Install

$ npm install --save abortable-promise-cache

Usage

const AbortablePromiseCache = require('abortable-promise-cache')

const cache = new AbortablePromiseCache({
    async fill(requestData, abortSignal) {
        // do some long-running thing
        return longRunningThing(requestData, abortSignal)
    }
})

// Make a cached request. The returned promise will abort with the given abort signal if
// there is not already a cached copy that has been resolved.
// Fill requests will be signaled to abort if all the requests for them
// so far have been aborted.
cache.get('some key', { ...anyStuff }, abortSignal)

// deleting and clearing will abort any outstanding requests
cache.delete('some key')
cache.clear()

API

Table of Contents

constructor

Parameters

  • args object constructor args
    • args.fill Function fill callback, will be called with sig fill(data, signal)
    • args.cache object backing store to use, must implement get(key), set(key, val), delete(key), and keys() -> iterator

get

Parameters

  • key any cache key to use for this request
  • data any data passed as the first argument to the fill callback
  • signal AbortSignal? optional AbortSignal object that aborts the request

delete

delete the given entry from the cache. if it exists and its fill request has not yet settled, the fill will be signaled to abort.

Parameters

  • key any

clear

Clear all requests from the cache. Aborts any that have not settled.

Returns number count of entries deleted

Academic Use

This package was written with funding from the NHGRI as part of the JBrowse project. If you use it in an academic project that you publish, please cite the most recent JBrowse paper, which will be linked from jbrowse.org.

License

MIT © Robert Buels