翻译:
将终止控制器/自动符号语义添加到承诺的缓存中。 每个 get
从缓存中可选择使用 AbortSignal 允许这样做的对象
请求中止.
如果全部 接到的请求在承诺达成之前中止.
如果填充请求在所有请求之前已经解决 中止, 它会留在缓存中 .
安装
$ npm install --save @gmod/abortable-promise-cache
使用量
import AbortablePromiseCache from '@gmod/abortable-promise-cache'
import QuickLRU from 'quick-lru'
const cache = new AbortablePromiseCache({
// QuickLRU is a good backing cache to use, but you can use any
// cache as long as it supports `get`, `set`, `delete`, and `keys`.
cache: new QuickLRU({ maxSize: 1000 }),
// the `fill` callback will be called for a cache miss
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.
const aborter = new AbortController()
const result = await cache.get('some key', { ...anyStuff }, aborter.signal)
// deleting and clearing will abort any outstanding requests
cache.delete('some key')
cache.clear()
API 密码
目录
学术用途
这一一揽子计划是利用来自 (原始内容存档于2018-09-21) (韩语). NHGRI 作为 页:1 J 浏览 项目。 如果你在学术中使用它 请引用最近发表的JBrowse论文 链接从 jbrowse.org (英语)。 。 。 .
许可证
麻省理工学院 罗伯特·布厄尔斯