Last active
August 29, 2015 14:22
-
-
Save nemisj/ffc3617e5c0615c02d5d to your computer and use it in GitHub Desktop.
Diff between async and yield-yield versions of postcss-cli
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 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); | |
} |
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 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