Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Created February 18, 2011 06:50
Show Gist options
  • Save ytnobody/833350 to your computer and use it in GitHub Desktop.
Save ytnobody/833350 to your computer and use it in GitHub Desktop.
jcue - javascript job-queueing engine

NAME

jcue - javascript job-queueing engine

SYNOPSIS

// create a new jcue object with 
jcue.clock = 100;

// put job-queue to jcue
jcue.put( function(){ ... } );

// And, jcue is going to work for jobs automatically... :)

AUTHOR

ytnobody

var jcue = { timer: -1 };
jcue.version = 0.01;
jcue.queue = new Array();
jcue.work = function(){
if ( typeof( this.queue ) != 'undefined' ) {
while ( this.queue.length > 0 ) {
q = this.queue.shift();
q();
}
jcue.stop();
}
};
jcue.run = function(){
if ( this.timer == -1 ) {
var self = this;
this.timer = setInterval( function(){ self.work() }, self.clock );
}
};
jcue.stop = function(){
clearInterval( this.timer );
this.timer = -1;
};
jcue.put = function( f ){
this.queue.push( f );
this.run();
};
/*
=head1 NAME
jcue - javascript job-queueing engine
=head1 SYNOPSIS
// create a new jcue object with
jcue.clock = 100;
// put job-queue to jcue
jcue.put( function(){ ... } );
// And, jcue is going to work for jobs automatically... :)
=head1 AUTHOR
ytnobody
=cut
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment