Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _ = require('underscore')
- Backbone = require('backbone')
- class Queue
- constructor: ->
- _.extend(@, Backbone.Events)
- @queue = []
- dequeue: =>
- if @queue.length
- callback() for callback in @queue
- @queue.length = 0
- whenCondition: (condition, callback)->
- isTrue = if typeof condition is 'function' then condition() else condition
- if isTrue
- callback()
- else
- @queue.push(callback)
- whenAvailable: (callback)=> @whenCondition(@available, callback)
- whenReady: (callback)=> @whenCondition(@ready, callback)
- whenLoaded: (callback)=> @whenCondition(@loaded, callback)
- module.exports = Queue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement