Skip to content

Instantly share code, notes, and snippets.

@nemisj
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemisj/ffc3617e5c0615c02d5d to your computer and use it in GitHub Desktop.
Save nemisj/ffc3617e5c0615c02d5d to your computer and use it in GitHub Desktop.
Diff between async and yield-yield versions of postcss-cli
function processCSS(processor, input, output, fn) {
function doProcess(css, fn) {
function onResult(result) {
if (typeof result.warnings === 'function') {
result.warnings().forEach(console.error);
}
fn(null, result.css);
}
var result = processor.process(css, {
safe: argv.safe,
from: input,
to: output
});
if (typeof result.then === 'function') {
result.then(onResult).catch(fn);
} else{
process.nextTick(onResult.bind(null, result));
}
}
async.waterfall([
async.apply(readFile, input),
doProcess,
async.apply(writeFile, output)
], fn);
}
var processCSS = require('yield-yield')(function* (processor, input, output) {
var css = yield readFile(input, yield);
function onResult(result) {
if (typeof result.warnings === 'function') {
result.warnings().forEach(console.error);
}
return result.css;
}
var result = processor.process(css, {
safe: argv.safe,
from: input,
to: output
});
if (typeof result.then === 'function') {
result = onResult(yield result);
} else{
result = onResult(result);
}
yield writeFile(output, result, yield);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment