Coder Social home page Coder Social logo

erikvold / cqueue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from avoidwork/cqueue

0.0 3.0 0.0 343 KB

Channel queue with Promises

Home Page: http://avoidwork.github.io/cqueue/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

cqueue's Introduction

cqueue

cqueue is a Channel queue for holding a msg/value until it's taken. Promises are used for concurrent operations against the queue.

build status

How do I use it?

Put something in the queue, and then take it at some point in the future. The queue can only hold one value, and the response will indicate what your machine should do, i.e. "continue" or "pause".

const cqueue = require("cqueue");
let chan = cqueue();

function handle (arg) {
    console.log(arg[1] || "empty");
}

chan.take().then(handle); // "empty"
chan.put("hello world");
chan.take().then(handle); // "hello world"

API

queue

Property

Array which can hold 1 value

put

Method

Puts an item into the Channel, and the Promise receives an Array

method put
param  {Mixed} arg Item
return {Object}    Promise
chan.put(arg).then(function(state) {
	if (state[0] === "continue") {
		// arg was added to the channel
	} else {
		// arg is not in the channel
	}
});

take

Method

Takes an item from the Channel, and the Promise receives an Array

method take
return {Object} Promise
chan.take().then(function(state) {
	if (state[0] === "continue") {
		// state[1] was taken from the channel
	} else {
		// state[1] is null
	}
});

License

Copyright (c) 2015 Jason Mulligan Licensed under the BSD-3 license.

cqueue's People

Contributors

avoidwork avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.