mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-20 12:55:47 +02:00
Move some screen utilities to the global util directory so that they can be used for other things too.
This commit is contained in:
30
lib/util/statequeue.js
Normal file
30
lib/util/statequeue.js
Normal file
@@ -0,0 +1,30 @@
|
||||
function StateQueue() {
|
||||
this.queue = []
|
||||
}
|
||||
|
||||
StateQueue.prototype.next = function() {
|
||||
return this.queue.shift()
|
||||
}
|
||||
|
||||
StateQueue.prototype.empty = function() {
|
||||
return this.queue.length === 0
|
||||
}
|
||||
|
||||
StateQueue.prototype.push = function(state) {
|
||||
var found = false
|
||||
|
||||
// Not super efficient, but this shouldn't be running all the time anyway.
|
||||
for (var i = 0, l = this.queue.length; i < l; ++i) {
|
||||
if (this.queue[i] === state) {
|
||||
this.queue.splice(i + 1)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
this.queue.push(state)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StateQueue
|
||||
Reference in New Issue
Block a user