enqueue
Enqueue a function to be called.
queue.enqueue(fn, context, args, meta)
Enqueues the fn function to be called with context as this and args as its arguments.
priorityQueue.enqueue( console.log, console, [ "world" ], { priority: 5 } );
priorityQueue.enqueue( console.log, console, [ "hello" ], { priority: 1 } );
priorityQueue.enqueue( console.log, console, [ "!" ], { priority: 7 } );
priorityQueue.flush();
// console.logs "hello"
// console.logs "world"
// console.logs "!"
A function can only be enqueued once.
Parameters
- fn
{function}:The function to be called.
- context
{Any}:The
thisthe function is called with. - args
{Array|Arguments}:The arguments the function is called with.
- meta
{Object|undefined}:Meta information about the task. This is where
priorityshould be provided. It defaults to0(highest priority) if a priority is not given.metaalso should include additional information useful for debugging. log will use:- log
{Array}: An array of values that will be passed toconsole.logwhen this task is enqueued or flushed. By default it is[fn.name]. - reasonLog
{Array}: An array of values that could be passed toconsole.logrepresenting why this task was scheduled.
- log