Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Created March 17, 2018 19:21
Show Gist options
  • Save Kelin2025/cb0f8f4f83396087d14688f9134e2c01 to your computer and use it in GitHub Desktop.
Save Kelin2025/cb0f8f4f83396087d14688f9134e2c01 to your computer and use it in GitHub Desktop.
Apicase queues
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