queuetry

1.0.12 • Public • Published

Introduction

asynchronous queue with retry(only peek at first, on success take) javascript implementation.

TOC

Installation

  1. Install node.js(assume you have allready)
  2. npm install queuetry

Example

playable at tonic

var Q = require('queuetry')
var q = Q()
var i = 0
var res = []
 
// put first synchronously (before get).
q.put("a")
 
// get what was allready put (above).
q.getAsync(function(item) {
    var j = [i++, item]
    console.log(j) // [0, 'a']
    res.push(j)
    return true // deleted from queue.
})
 
// async get because no put
q.getAsync(function(item) {
    var j = [i++, item]
    console.log(j) // [1, 'b']
    res.push(j)
    return false // peeked from queue, next successfull getAsync() will delete.
})
 
// async get because no put
q.getAsync(function(item) {
    var j = [i++, item] // [2, 'b']
    console.log(j)
    res.push(j)
    return true
})
 
q.put("b") // put after get.
 
// Expected output =>
// [ 0, 'a' ]
// [ 1, 'b' ]
// [ 2, 'b' ]

API

Queuetry

Creates queue with retry with capacity of 16.

Queuetry(int capacity)

Creates a queue with retry with length of len.

put(item)

Put item in queue.

getAsync(f)

take item from queue, but only if f returns true.

Code coverage

======== Coverage summary ========
Statements   : 100% ( 17/17 )
Branches     : 100% ( 6/6 )
Functions    : 100% ( 3/3 )
Lines        : 100% ( 17/17 )
==================================

Acknowledgement

Many thanks to in no particular order:

Readme

Keywords

Package Sidebar

Install

npm i queuetry

Weekly Downloads

0

Version

1.0.12

License

ISC

Last publish

Collaborators

  • alfredwesterveld