Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sync usage #584

Closed
ArmorDarks opened this issue Aug 27, 2016 · 8 comments
Closed

Allow sync usage #584

ArmorDarks opened this issue Aug 27, 2016 · 8 comments

Comments

@ArmorDarks
Copy link

It would be great if async usage would be optional

So far forceful usage of async in SVGO causes a lot of pain in libraries, which can't handle natively async calls. For example, some templates language doesn't play well with it at all.

Any chances for optional sync implementation?

@ArmorDarks
Copy link
Author

ArmorDarks commented Aug 28, 2016

I see some efforts have been made here #580, though, they didn't succeed.

@GreLI
Copy link
Member

GreLI commented Nov 20, 2016

I'm afraid the only option use it sync is to wait for execution in command prompt.

@GreLI GreLI closed this as completed Nov 20, 2016
@ArmorDarks
Copy link
Author

<irony>10 out of 10 solution</irony>

@yvele
Copy link

yvele commented Dec 9, 2016

@ArmorDarks It's maybe a bit ugly but you can make a hack using deasync

import SVGO from "svgo";
import deasync from "deasync";

function svgoOptimizeSync(svgo, content) {
  let res;
  svgo.optimize(content, result => res = result);
  deasync.loopWhile(() => !res);
  return res;
}

PS: I've made a gist of it

@ArmorDarks
Copy link
Author

@yvele Thanks for additional solution. Unfortunately, it implies additional dependency or a hack, which we'd like to avoid.

I think the real issue here is that SVGO does not use promises and instead relies on callback. Otherwise it would be very easy to do with async function. But as right of now, we're forced to use deascyn-like hacks, or use some means to promisify SVGO, which, I'd say, isn't ok on 2017.

Though, I don't want to insult developers. SVGO is great library and it saved us like a ton of kbs and time.

@GreLI
Copy link
Member

GreLI commented Aug 4, 2017

SVGO has appeared when there was no promises.

@ArmorDarks
Copy link
Author

Yeap, I know.

brewingcode added a commit to brewingcode/pug-pack that referenced this issue Sep 22, 2017
Because we are now doing the file transforms in the Pug filter, we have
to be syncronous. All the filter-specific transforms have been moved to
the transform() method.

Note that .json and .yml files are NOT in the transform() method, they
stay as Pug variables.

See deasync for a possible (ugly) workaround for svgo:

svg/svgo#584 (comment)
@GreLI
Copy link
Member

GreLI commented Oct 31, 2017

SVGO.optimize() now returns Promise in v1.0.0.

brewingcode added a commit to brewingcode/pug-pack that referenced this issue Feb 24, 2020
Because we are now doing the file transforms in the Pug filter, we have
to be syncronous. All the filter-specific transforms have been moved to
the transform() method.

Note that .json and .yml files are NOT in the transform() method, they
stay as Pug variables.

See deasync for a possible (ugly) workaround for svgo:

svg/svgo#584 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants