Make sure specified function runs one at a time
CoffeeScript JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Why Queued Function?

In some cases, (for example adding users to linux box) if you try to run your functions in parallel it will fail. And you need very lightweight queue functionality without adding any complexity to your project.

You want to have very simple queue, that will register each incoming function, and execute it one by one.

For example (in coffeescript, for js version, scroll below):

	qfunction = require "qfunction"

	# here is an example function 
	# that will callback after 1 second.
	exampleFunction = (x,callback)-> setTimeout (()-> callback "Finished in 1 sec...with #{x} #{}"),1000

	# if you run the for-loop below, 
	# they will approximately all finish at the same time
	for i in [0..10] 
	 exampleFunction i,(r)->
	  console.log "regular function out:",r
	# now you can create a queued version of this function, 
	# and it will finish in 10 seconds, 
	# running one after another
	queuedExampleFunction = qfunction exampleFunction

	for i in [0..10]
	  queuedExampleFunction i,(r)->
	   console.log "queued function out:",r


$ npm install qfunction

To do

- Queue can be persisted to a db (right now, pending functions will die if node process dies)
- Functions that don't have a callback can be serialized (however, i don't know why those need to be serialized)

Example in JS

	var exampleFunction, i, qfunction, queuedExampleFunction;
	qfunction = require("qfunction");

	exampleFunction = function(x, callback) {
	  return setTimeout((function() {
	    return callback("Finished in 1 sec...with " + x + " " + (;
	  }), 1000);

	for (i = 0; i <= 10; i++) {
	  exampleFunction(i, function(r) {
	    return console.log("regular function out:", r);

	queuedExampleFunction = qfunction(exampleFunction);
	for (i = 0; i <= 10; i++) {
	  queuedExampleFunction(i, function(r) {
	    return console.log("queued function out:", r);