qoo

0.1.0 • Public • Published

qoo Circle CI

Expressive middleware for queue workers

Task

A task is exposed to the middleware chain as this. A task must implement the following interface.

  • value
  • resolve function (result) { /* ... */ }
  • reject function (error) { /* ... */ }

Optional methods can be attached to a task e.g.

Example

firebase-queue

import compose from 'qoo'
import Firebase from 'firebase'
import Queue from 'firebase-queue'
 
const xf = (value, progress, resolve, reject) => {
  return { value, progress, resolve, reject }
}
 
function * logger (next) {
  const start = new Date()
  yield next
  const ms = new Date() - start
  console.log('%j - %s', this.value, ms)
}
 
function * processor (next) {
  this.result = { foo: 'bar' }
  yield next
}
 
const ref = new Firebase('https://<your-firebase>.firebaseio.com/queue')
const queue = new Queue(ref, compose(xf, logger, processor))

nsq.js

import nsq from 'nsq.js'
import compose from 'qoo'
 
const xf = (msg) => {
  return {
    value: msg.json(),
    resolve: msg.finish.bind(msg),
    reject: msg.requeue.bind(msg)
  }
}
 
function * logger (next) {
  const start = new Date()
  yield next
  const ms = new Date() - start
  console.log('%j - %s', this.value, ms)
}
 
function * processor (next) {
  this.result = { foo: 'bar' }
  yield next
}
 
const reader = nsq.reader()
reader.on('message', compose(xf, logger, processor))

Badges

js-standard-style

Readme

Keywords

Package Sidebar

Install

npm i qoo

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • hden