feature | Promises | streams | generators |
---|---|---|---|
asynchronous (can push from inner callbacks) |
true | true | false |
multiple push | false | true | true |
error catch | true | false | false |
error forwarding | true | false | true |
external dependency is a must | false | true | false |
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
function when(value, func) { | |
var promise = Promise.cast(value); | |
if (func) { | |
promise = promise.then(function (value) { | |
return Promise.cast(func(value)).then(function (newValue) { | |
return newValue === undefined ? value : newValue; | |
}); | |
}); | |
} |
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
var stream = require('stream'); | |
var Rx = require('rx'); | |
var util = require('util'); | |
function ObservableStream(transform) { | |
stream.Duplex.call(this, {objectMode: true}); | |
this.subject = new Rx.Subject(); | |
this.observable = transform(this.subject); | |
this.subscription = null; |
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
// just for RequireBin | |
console.log = function () { | |
var pre = document.createElement('pre'); | |
pre.textContent = Array.prototype.map.call(arguments, function (arg) { | |
return typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg; | |
}).join(' '); | |
document.body.appendChild(pre); | |
}; | |
var esprima = require('esprima-fb'), ast; |
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
function Template(str, data) { | |
return str.replace(/\${([^}]+)}/g, (_, name) => data[name]); | |
} | |
var answer = 42; | |
(function () { | |
var answer = 60; | |
console.log(Template('Answer is ${answer}', {answer})); | |
})(); |
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
### Keybase proof | |
I hereby claim: | |
* I am RReverser on github. | |
* I am rreverser (https://keybase.io/rreverser) on keybase. | |
* I have a public key whose fingerprint is 3456 B5A0 0E7F 67D8 A049 5B85 7634 8879 1722 011A | |
To claim this, I am signing this object: |
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
/* | |
The MIT License (MIT) | |
Copyright (c) 2015 Ingvar Stepanyan | |
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 |
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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var acorn = require('./parser'); | |
var transform = require('./transform'); | |
var escodegen = require('escodegen'); | |
var filename = process.argv[2]; | |
if (!filename) { | |
console.log('Usage: transpile filename.js'); |
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
var createChain = function (ops) { | |
var chain = function () {}; | |
chain.__asyncOps = ops; | |
return new Proxy(chain, AsyncContextHandler); | |
}; | |
function AsyncAccessError() { | |
TypeError.call(this, 'Can\'t perform synchronous operation on remote object.'); | |
} |
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
function awaitableVersionOf(nodeFunction) { | |
return (...args) => new Promise((resolve, reject) => { | |
nodeFunction( | |
...args, | |
(error, ...cbArgs) => error ? reject(error) : resolve(...cbArgs) | |
); | |
}); | |
} |
OlderNewer