Created
March 17, 2018 19:21
-
-
Save Kelin2025/cb0f8f4f83396087d14688f9134e2c01 to your computer and use it in GitHub Desktop.
Apicase queues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApiQueue } from '@apicase/core' | |
/* Create queue */ | |
const queue = new ApiQueue() | |
/* Push requests */ | |
queue.push(doRequest, { url: '/posts' }) | |
queue.push(Service.doRequest, { body }) | |
/* Global queue events */ | |
queue.on('done', console.log) | |
queue.on('fail', console.log) | |
queue.on('cancel', console.log) | |
/* .push() returns request */ | |
const req = queue.push(doRequest, payload) | |
/* Requests removal */ | |
queue.remove(req) | |
/* Getting currently running request */ | |
queue.current.on('done', console.log) | |
/* | |
remove() calls req.cancel() | |
so this one will cancel all queue | |
*/ | |
queue.remove(queue.current) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment