Skip to content

Commit

Permalink
Merge pull request #1 from uhop/master
Browse files Browse the repository at this point in the history
Minor editing to make code readable...
  • Loading branch information
nrstott committed Jan 9, 2012
2 parents c3644b7 + db273e0 commit 75c6f93
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions jsgi/jsgib.md
Expand Up @@ -88,27 +88,28 @@ the iteration is completed.

### Example

function SimpleAsyncForEachable() {
var values = [1,2,3,4]
, deferred = q.defer();

this.forEach = function(callback) {
function next() {
if (values.length > 0) {
setTimeout(function() {
// Simulate Async Stream
callback(values.shift());
next();
}, 0);
} else {
deferred.resolve();
function SimpleAsyncForEachable() {
var values = [1,2,3,4]
, deferred = q.defer();

// WTF: what is `this` in this context?
this.forEach = function(callback) {
function next() {
if (values.length > 0) {
setTimeout(function() {
// Simulate Async Stream
callback(values.shift());
next();
}, 0);
} else {
deferred.resolve();
}
}

return deferred.promise;
}
}

return deferred.promise;
}
}

### Reasons for JSGI B

JSGI B is intended to unify the concepts of JSGI A Applications and Middleware and redefine Application as a term
Expand Down Expand Up @@ -153,21 +154,21 @@ in an effort to make JSGI more consistent with existing JavaScript means of repr

### Middleware Example

function LogRequest(req, next) {
writeToLog(new Date(), JSON.strigify(req)); // assume writeToLog is defined elsewhere
return next(req);
}

function NotFound(req, next) {
var deferred = q.defer();
te
(next, deferred.resolve, function onRejection() {
return {
status: 404,
body: [ 'Not Found' ],
headers: { 'content-type': 'text/plain' }
function LogRequest(req, next) {
writeToLog(new Date(), JSON.strigify(req)); // assume writeToLog is defined elsewhere
return next(req);
}
})

return deferred.promise;
}
function NotFound(req, next) {
var deferred = q.defer();
te // WTF: te???
(next, deferred.resolve, function onRejection() {
return {
status: 404,
body: [ 'Not Found' ],
headers: { 'content-type': 'text/plain' }
}
})

return deferred.promise;
}

0 comments on commit 75c6f93

Please sign in to comment.