With the power of await, this isn't so difficult:

let nacl, scrypt;

function main() {
	/* Synchronous code that calls nacl and scrypt */
}

(async () => {
	[nacl, scrypt] = await Promise.all([new Promise(nacl_factory.instantiate), new Promise(scrypt_module_factory)]);
	return main();
})();

Leave a Reply

Your email address will not be published.

Warning: This site uses Akismet to filter spam. Until or unless I can find a suitable replacement anti-spam solution, this means that (per their indemnification document) all commenters' IP addresses will be sent to Automattic, Inc., who may choose to share such with 3rd parties.
If this is unacceptable to you, I highly recommend using an anonymous proxy or public Wi-Fi connection when commenting.