asar icon indicating copy to clipboard operation
asar copied to clipboard

Any way to synchronously create a package programatically?

Open GNUGradyn opened this issue 4 years ago • 1 comments

Hi! I noticed asar.createPackage is a couroutine. I need to synchronously create a package programatically?

GNUGradyn avatar Apr 17 '21 04:04 GNUGradyn

I believe this was intentional. This library used to be completely synchronous (which is why I made asar-async), but it was very frustrating because your entire program would have to stop until the package was finished, which took up way more time than it needed to. I'd suggest you look into async functions and promises, since that will provide a similar programming style to synchronous calls.

Here's some good documentation on it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

Typically, when I'm writing a one-off script and need something to be synchronous when it's not, I'll use an IIFE (immediately-invoking function expression). Here's what it looks like:

(async () => {
    // Your code goes here
    const myThing = await anAsyncFunction();
    console.log(myThing);
})();

sploders101 avatar May 04 '21 17:05 sploders101