内容简介:Resolve or reject only last Promise.Useful if you want to "abort" already running async operations started with debounced input event.When calling the wrapper function multiple times, only the last returned
only-last-promise
Resolve or reject only last Promise.
Useful if you want to "abort" already running async operations started with debounced input event.
Install
npm install only-last-promise --save
Usage
When calling the wrapper function multiple times, only the last returned Promise
will resolve or reject and all other Promise
s will be aborted with DiscardSignal
error.
In the following example, fetch
requests for /buddy
and /allie
will be discarded (they will return undefined
), and only /becky
will be resolved with
Response
.
import onlyLastPromise, { DiscardSignal } from 'only-last-promise'; const wrapper = onlyLastPromise(); const wrappedFetch = async (url) => { try { return await wrapper(fetch(url)); } catch (error) { if (!(error instanceof DiscardSignal)) { throw error; } } }; (async () => { await Promise.all([ wrappedFetch('/buddy'), wrappedFetch('/allie'), wrappedFetch('/becky') ]); // => [undefined, undefined, Response] })();
API
onlyLastPromise()
Returns: Function
Factory function which returns wrapper function.
wrapper(promise)
Type: Function
promise
Type: Promise
Promise
to handle.
Browser support
Tested in IE9+ and all modern browsers, assuming Promise
is available.
Test
For automated tests, run npm run test:automated
(append :watch
for watcher
support).
License
MIT © Ivan Nikolić
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
云计算安全与隐私
Tim Mather、Subra Kumaraswamy、Shahed Latif / 刘戈舟、杨泽明、刘宝旭 / 机械工业出版社华章公司 / 2011-6 / 65.00元
《云计算安全与隐私》可以使你明白当把数据交付给云计算时你所面临的风险,以及为了保障虚拟基础设施和网络应用程序的安全可以采取的行动。本书是由信息安全界知名专家所著,作者在书中给出许多中肯的忠告和建议。本书的读者对象包括:IT职员、信息安全和隐私方面的从业人士、业务经理、服务提供商,以及投资机构等。阅读本书你会了解直到现在还严重匮乏的云计算安全方面的详尽信息。 《云计算安全与隐私》主要内容包括:......一起来看看 《云计算安全与隐私》 这本书的介绍吧!