asciify
asciify copied to clipboard
Can we have a sync version while using as node module?
Do you really really need it? asciify loads a file off disk to get the font, so making that sync would tie up the event loop while the disk IO occurred. It's usually a bad idea to force node to do things sync style, so I'm keen to avoid endorsing that, and instead keep this module as simple as possible.
The ask is for a sync version along with async and the reason is that my program exists without display the ascii text if there is an error or something similar. I am aware that I can do it in a callback but just thought that it would be nice to have a sync version like we have in the core node library for reading file? I am fine if it's going against the design.
Hi Oli,
I kind of also have a similar need. Though there may be another method to do this (please feel free to suggest as I am a newbie with yo/js). However I am not able to figure this out.
I need to get the return value back to main program. So essentially trying to do this:
asciify(' ' + _.capitalize(this.name), {font:'slant'}, function (err, res) {
this.banner = res;
});
writeToFile('output.txt', this.banner);
I need the banner value captured so it can be written to a file. This is for a 'yo' generator. Just to add, there is a lot of logic/code after the capture of banner value so I cannot simply add that to callback.
How do I do this?
Thanks Amit
@amitjindal did you see https://github.com/olizilla/grunt-asciify
it sets a property with the asciified text when it's available: https://github.com/olizilla/grunt-asciify/blob/master/tasks/asciify.js#L25
...and grunt handles the async issue by providing a done
callback function, so the next task waits on asciify to complete, so we can assume the property is available to subsequent tasks.
If that's not relevant, then you could take a peek at one of the other yo generators using it: https://www.npmjs.com/browse/depended/asciify
and see how they do.
Thanks for the tip. After a few trials I figured it out. Very weird syntax. But now it works.
MyClass.prototype.createBanner = function createBanner(text) {
var cb = this.async();
asciify(text, {font:'slant'}, function (err, res) {
this.banner = res;
cb();
}.bind(this));
};
Later in the code:
this.createBanner(' ' + _.capitalize(this.baseName));
console.log(this.banner);