benbahrenburg / Ti.Queue

Queueing in Titanium made easy - CommonJS module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ti.Queue

Pure JavaScript Queueing for Titanium

Features

* Ability to create persistent (named) or session based queues. * LIFO and FIFO support * Is a single CommonJS file so easy to modify

How to install

Installing Ti.Queue is straightforward, simply copy the ti.queue.js file into your Titanium project.

Since Ti.Queue is a CommonJS module, can you import the module anywhere in your app by simply using the require method.

For example:

var mod = require('Ti.Queue');

Sample

First requre the module into our project

var mod = require('Ti.Queue');

Next create a named queue

  //providing a new automatically creates a persistent queue
  //if no name is provided a session queue is created
  var queue = new mod("demo");

Then add a job to the queue

queue.enqueue({title:'Sample 1', message:'hello world'});

You can peek at the next value in the queue

Ti.API.info('Peek value: ' + JSON.stringify(queue.peek());

By calling dequeue you pop the next job from the queue.

var job = queue.dequeue();

(!) If a name is provided to the queue the next time you create a queue with the same name any jobs queued will be re-loaded. Otherwise the queue will only hold the jobs for a session.

Example app.js

Please download the demo project's [app.js](https://github.com/benbahrenburg/Ti.Queue/blob/master/app.js) for a complete sample.

Licensing & Support

This project is licensed under the OSI approved Apache Public License (version 2). For details please see the license associated with each project.

Developed by Ben Bahrenburg available on twitter @benCoding

Learn More

Twitter

Please consider following the @benCoding Twitter for updates and more about Titanium.

Blog

For module updates, Titanium tutorials and more please check out my blog at benCoding.Com.

About

Queueing in Titanium made easy - CommonJS module

License:Other


Languages

Language:JavaScript 100.0%