-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from jtwebman/fix-nested-async-helpers
Got nested async helpers working
- Loading branch information
Showing
11 changed files
with
221 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_'; | ||
|
||
function generateId(length) { | ||
if (!length) { | ||
length = 8; | ||
} | ||
var res = ''; | ||
for (var i = 0; i < length; ++i) { | ||
res += alphabet[Math.floor(Math.random() * alphabet.length)]; | ||
} | ||
return res; | ||
} | ||
|
||
module.exports = generateId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
var Promise = require('bluebird'); | ||
|
||
var generateId = require('./generate-id'); | ||
|
||
var ID_LENGTH = 8; | ||
var MS_CHECK_TIME = 10; | ||
var ID_PREFIX = '__aSyNcId_<_'; | ||
var ID_SUFFIX = '__'; | ||
|
||
function resolve(cache, fn, context) { | ||
var id = ID_PREFIX + generateId(ID_LENGTH) + ID_SUFFIX; | ||
cache[id] = new Promise(function(passed, failed) { | ||
try { | ||
fn(context, function(res) { | ||
passed(res); | ||
}); | ||
} catch(error) { | ||
failed(error); | ||
} | ||
}); | ||
return id; | ||
} | ||
|
||
function done(cache, callback) { | ||
Promise.props(cache).then(function(values) { | ||
callback(null, values); | ||
}).catch(function(error) { | ||
callback(error); | ||
}); | ||
} | ||
|
||
function hasResolvers(text) { | ||
if (text.search(ID_PREFIX) > 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
module.exports = { | ||
done: done, | ||
hasResolvers: hasResolvers, | ||
resolve: resolve | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{{#contentFor "title"}} | ||
Failer | ||
{{/contentFor}} | ||
<span id="text">This should fail {{#failer}}for sure{{/failer}}.</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.