Skip to content
Browse files

now fully documented

  • Loading branch information...
1 parent 9565b85 commit 8bae4827328947b282fdc267b45ff9d3721750cc @substack committed Jan 17, 2012
Showing with 71 additions and 0 deletions.
  1. +71 −0 README.md
View
71 README.md
@@ -66,7 +66,78 @@ user 5 in spot 2
methods
=======
+var waitlist = require('waitlist')
+var ws = waitlist()
+-------------------
+
+Create a new waitlist.
+
+ws.add(name, res)
+-----------------
+
+Add a new resource `name` with the resource object `res`.
+`res` will be made available to consumers.
+
+ws.remove(name)
+---------------
+
+Remove a resource by its `name`.
+
+ws.acquire(time, emit)
+----------------------
+
+Try to acquire an available resource for `time` milliseconds.
+
+If `time` is 0, the session won't expire automatically.
+
+Resource events will be passed through the `emit` function supplied.
+
+ws.release(token)
+-----------------
+
+Release a granted token.
+
+ws.on('stats', cb)
+------------------
+
+Emitted whenever the queue stats of available resources and connected clients
+changes. `cb(stats)` is called with the `ws.stats` object which looks like:
+
+``` js
+{ resources : 2, waiting : 0, using : 1 },
+```
+
+resource events
+===============
+
+The `emit` function passed to `ws.acquire()` receives these events:
+
+'token', token
+--------------
+
+Emits the token for the current session right after `acquire()` is called.
+
+'spot', ix
+----------
+
+If the resource isn't available right away, emit the position in the queue.
+
+'available', res, name, time
+----------------------------
+
+Emitted when a resource `res` with the name `name` is ready for `time`
+milliseconds of use.
+
+'expire'
+--------
+
+Emitted when a session's alloted time is up.
+
+'release'
+---------
+
+Emitted when a session is finished either through `ws.release()` or expiry.
install
=======

0 comments on commit 8bae482

Please sign in to comment.
Something went wrong with that request. Please try again.