Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Can we have a sync version while using as node module? #5

vishr opened this Issue Nov 21, 2013 · 5 comments


None yet
3 participants

vishr commented Nov 21, 2013

No description provided.


olizilla commented Nov 21, 2013

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.

vishr commented Nov 21, 2013

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?



olizilla commented Jun 5, 2015

@amitjindal did you see https://github.com/olizilla/grunt-asciify

it sets a property with the asciified text when it's available:

...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;

Later in the code:

this.createBanner(' ' + _.capitalize(this.baseName));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment