-
-
Save glennblock/2394695 to your computer and use it in GitHub Desktop.
//this does not work because exists does not accept a standard callback | |
function createRequiredFilesIfNotPresent(_) { | |
var baseFolder = process.cwd(); | |
var exists = path.exists(baseFolder + "/server.js"); | |
log.info(exists); | |
} | |
//using a wrapper function however works. Log entries added for sequence. | |
function exists(p, callback) { | |
path.exists(p, function(e) { | |
callback(null, e); | |
}); | |
} | |
function createRequiredFilesIfNotPresent(_) { | |
var baseFolder = process.cwd(); | |
log.info("check exists start"); | |
var p1 = exists(baseFolder + "/server.js", _); | |
log.info("exists:" + p1); | |
log.info("check exists complete"); | |
} |
Yes, I could provide a small library with it, or at least document it. I want to write a FAQ but I keep getting dragged into other things, like blog articles.
I don't want to put it directly into streamline's runtime though because I want to keep streamline at the language level. It runs in the browser too.
Yes.
I have bundled a helper for streams because streams have an event API that does not work too well with streamline. So I have introduced a callback API on top of it that works much better with streamline. I did it because this is a non trivial thing and it makes a big difference in usability.
But I did not take care of all the corner cases of the node API. I could introduce a nodeutils
module with other wrappers. I'll do it when I get time.
I track all this through the GitHub issues system. So if you want to enter the suggestion there please do it. Otherwise, I'll do it.
Bruno
Sure. My skype is offline most of the time but I'll turn it on. But that won't be before tomorrow as I'm travelling today.
Forgot. my skype id is bjouhier
Hi Glenn,
Yes, the vast majority of node callback based core APIs take a standard callback.
path.exist
is an exception and the littleexists
wrapper that you wrote is the way to deal with it.There is also another gotcha with core APIs: the "futures" feature does not work directly with them, it only works with the functions that you have written in streamline.
One remark: you should swap lines 20 and 21. Also you can directly write: