Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 180d70a01fd64dd10a3e5d541634ad7068ad3be8 @iizukanao committed Aug 24, 2011
Showing with 1,135 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +8 −0 .npmignore
  3. +22 −0 LICENSE
  4. +9 −0 Makefile
  5. +87 −0 README.md
  6. +184 −0 lib/sequent.js
  7. +16 −0 package.json
  8. +119 −0 src/sequent.coffee
  9. +247 −0 test/01_all.coffee
  10. +340 −0 test/01_all.js
  11. +31 −0 test/02_wait.js
  12. +38 −0 test/03_queue.js
  13. +29 −0 test/04_mature.js
@@ -0,0 +1,5 @@
+.DS_Store
+*~
+*.swp
+*.swo
+node_modules/
@@ -0,0 +1,8 @@
+*.swp
+*.swo
+*~
+.git*
+Makefile
+src/
+test/
+node_modules/
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2011 Nao Iizuka <iizuka@kyu-mu.net>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
+all:
+ rm -rf lib
+ coffee -o lib src
+ coffee -c test/*.coffee
+
+test:
+ @@vows test/*.js
+
+.PHONY: test
@@ -0,0 +1,87 @@
+sequent
+=======
+
+JavaScript async flow control
+
+How to use
+----------
+
+### Wait (Join) ###
+
+Execute after expected number of seq.done() are executed.
+
+ var Sequent = require('sequent');
+ var seq = new Sequent;
+
+ setTimeout(function(){
+ seq.done("done 1"); // Arguments are optional
+ }, 500);
+
+ setTimeout(function(){
+ seq.done("done 2", "end");
+ }, 1000);
+
+ // Wait for two seq.done()
+ seq.wait(2, function(arg1, arg2){
+ // arg1 == "done 2", arg2 == "end"
+ console.log("all done");
+ });
+
+### Break (as in `for` loops) ###
+
+Exit waiting earlier than planned.
+
+ var Sequent = require('sequent');
+ var seq = new Sequent;
+
+ seq.wait(100, function(arg){
+ // arg == "matured"
+ });
+
+ for (var i=0; i<100; i++) {
+ if (i == 5) {
+ // Break here and go to callback of wait()
+ seq.mature("matured");
+ }
+
+ // seq.done() after seq.mature() are ignored
+ seq.done("done " + i);
+ }
+
+### Queue (execute in order) ###
+
+Execute functions in queued order when it available.
+
+ var Sequent = require('sequent');
+ var seq = new Sequent;
+
+ var funcs = [];
+ var results = [];
+ for (var i=1; i<=10; i++) {
+ // Functions will be executed in seq.queue()'d order.
+ // seq.queue() returns a wrapped function.
+ funcs.push(seq.queue(
+ (function(_i){
+ return function(){
+ results.push(_i);
+ }
+ })(i)
+ ));
+ }
+
+ funcs.reverse();
+
+ // Mark queued functions as available
+ for (var i=0, l=funcs.length; i<l; i++) {
+ funcs[i]();
+ }
+
+ // Wait for all queued functions to be executed
+ seq.flush(function(){
+ // results is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+ });
+
+Installation
+------------
+
+ npm install sequent

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,16 @@
+{
+ "name": "sequent"
+ , "description": "JavaScript async flow control"
+ , "version": "0.1.0"
+ , "keywords": ["sequent", "sequence", "flow", "control", "queue", "join", "wait"]
+ , "author": "Nao Iizuka <iizuka@kyu-mu.net>"
+ , "main": "./lib/sequent"
+ , "homepage": "https://github.com/iizukanao/sequent"
+ , "repository": {
+ "type": "git",
+ "url": "git://github.com/iizukanao/sequent.git"
+ }
+ , "devDependencies": {
+ "vows": ">= 0.5.9"
+ }
+}
Oops, something went wrong.

0 comments on commit 180d70a

Please sign in to comment.