Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit d72c144

Browse files
author
Necati Özal
committed
New features were added.
Index can be specified by run method. Entry methods are using the run method as a referance. Steps can be specified by prev and next methods by this way.
1 parent 9a54eb5 commit d72c144

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ queue.put(callback, arg1, arg2, ..., argX)
1212
------------------------------------------
1313
You can add your methods to the current state of the queue by ***put*** method.
1414

15-
queue.run()
15+
queue.run(index = 0)
1616
-----------
1717
You can start the queue by ***run*** method.
1818

1919
---
2020

21-
queue.wait(milliseconds)
21+
queue.wait(milliseconds, steps = 1)
2222
------------------------
2323

2424
queue.skip(steps)
@@ -29,13 +29,13 @@ queue.reset()
2929

3030
---
3131

32-
entry.next()
32+
entry.next(steps = 1)
3333
------------
3434
You can run the next entry in the queue by ***next*** method.
3535

36-
entry.prev()
36+
entry.prev(steps = 1)
3737
------------
38-
You can run the next entry in the queue by ***next*** method.
38+
You can run the next entry in the queue by ***prev*** method.
3939

4040
---
4141

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "QueueJS",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Queue JS is a simple library which can call your methods in a order you specify.",
55
"main": "queue.js",
66
"authors": [

queue.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@
1515
put: function(callback, argArray) {
1616
this.splice(this.index+1, 0, new Entry(this, callback, [].slice.call(arguments, 1)));
1717
},
18-
run: function() {
18+
run: function(index) {
19+
if(!index ) {
20+
index = this.index;
21+
}
22+
1923
var entry;
20-
if( entry = this[this.index] ) {
24+
if( entry = this[index] ) {
25+
this.index = index;
2126
return entry.callback.apply(entry, entry.argArray);
2227
}
2328
return null;
2429
},
2530

26-
wait: function(ms) {
31+
wait: function(ms, steps) {
2732
this.put(function() {
28-
window.setTimeout(this.next.bind(this), ms);
33+
window.setTimeout(this.next.bind(this,steps), ms);
2934
});
3035
},
31-
skip: function(count) {
36+
skip: function(steps) {
3237
this.add(function() {
33-
this.queue.index += count;
38+
this.queue.index += steps;
3439
this.next();
3540
});
3641
},
@@ -53,21 +58,11 @@
5358
this.argArray = argArray;
5459
};
5560
Entry.prototype = {
56-
next: function() {
57-
var queue = this.queue;
58-
59-
if( queue.index+1 in queue ) {
60-
return queue.run(queue.index++);
61-
}
62-
return null;
61+
next: function(steps) {
62+
return this.queue.run(this.queue.index+(steps||1));
6363
},
64-
prev: function() {
65-
var queue = this.queue;
66-
67-
if( queue.index-1 in queue ) {
68-
return queue.run(queue.index--);
69-
}
70-
return null;
64+
prev: function(steps) {
65+
return this.next(-steps);
7166
}
7267
};
7368

0 commit comments

Comments
 (0)