QFI - a function processing queue for node.js
qfi ( /ˈkjuːfi/; named cue-fi) is the love child of an array and an eventemitter
it supports all
- and eventemitter http://nodejs.org/docs/v0.4.7/api/events.html
methods and properties. this is allready useful in itself, but there is more.
qfi supports various native methods to
- usefull if you work with REST APIs that have rate limits.
- zillion other things
var q = require('/path/to/qfi.js');
or via npm
>npm install qfi var q = require('qfi');
the 'q' part of 'qfi'
//if true, q is in daemon mode (q waits for new things to execute) //default false q.daemon //time between executions, default 0 q.outtime //a precondition callback //if true, the execution loop breaks //per default returns false q.breakIf() //if the loop breaks, this callback is called q.breakcallback(pointer) //if the exectuion loop exits, this callback is called q.exitcallback()
//returns a new FunctionItem q.createFunctionItem(func, args, thisarg, eventname) //adds a new FunctionItem to q //more details see the section about FunctionItem q.add(func, args, thisarg, eventname) //=== q.addFunctionItem(func, args, thisarg, eventname) //set the properties of q q.setConf(confobject) //start an execution loop //executes all stored FunctionItems, starting from q //takes an optional conf object -> see q properties q.start(conf) // === q.restart(conf) //stop a currently running execution loop q.stop(conf) //if the execution loop was stopped //`resume` continues execution from where it was stopped q.resume(conf) //executes all FunctionItems starting from q[start] q.startAt(start, conf) //stops execution before q[stop] gets executed q.breakBefore(stop,conf) //stops execution after q[stop] was executed q.breakAfter(stop,conf) //deletes the break set with q.breakBefore or q.breakAfter q.clearBreak(stop,conf) //start execution from q[start], stop execution before q[stop] q.startAtbreakBefore(start, stop, conf) //pauses execution for `milsec` milseconds //q.pause(milsec,conf) //start daemon mode //q waits for new FunctionItems get added (and then executes them) q.startDaemon() //turn of daemon mode q.stopDaemon() //define how fast the FunctionItems in q get executed (how many `hits`(executions) during `milisec`) //q.setRate(hits, milsec) //how many executions should happen in one second q.setSecondRate(hits) //how many executions should happen in one minute/hour/day q.setMinuteRate() q.setHourlyRate() q.setDailyRate() //add an event listener to q //inherited from eventemitter q.on(eventname, callback) //create a new (blank) q var q2 = q.create()
the 'fi' part of 'qfi'
//stores a function q[n].func //storeas an arguements array q[n].args //stores a `this` value of `func` q[n].thisarg //after `func` gets executed, this event is emitted (with the returnvalue of `func`) //note: very cool and powerful q[n].eventname //note: if no eventname is given, no event will be emitted