{"id":1346,"date":"2021-07-21T19:05:54","date_gmt":"2021-07-21T19:05:54","guid":{"rendered":"https:\/\/www.ishygddt.xyz\/~blog\/?p=1346"},"modified":"2022-03-08T18:41:05","modified_gmt":"2022-03-08T18:41:05","slug":"javascript-calling-async-init-libs-from-sync-code","status":"publish","type":"post","link":"http:\/\/www.ishygddt.xyz\/~blog\/2021\/07\/javascript-calling-async-init-libs-from-sync-code","title":{"rendered":"Javascript: calling asynchronously-initialized libraries from synchronous code"},"content":{"rendered":"<p>With the power of <code class=\"language-javascript\" data-line=\"\">await<\/code>, this isn't so difficult:<\/p>\n<pre><code class=\"language-javascript\" data-line=\"\">let nacl, scrypt;\n\nfunction main() {\n\t\/* Synchronous code that calls nacl and scrypt *\/\n}\n\n(async () =&gt; {\n\t[nacl, scrypt] = await Promise.all([new Promise(nacl_factory.instantiate), new Promise(scrypt_module_factory)]);\n\treturn main();\n})();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>With the power of await, this isn't so difficult: let nacl, scrypt; function main() { \/* Synchronous code that calls nacl and scrypt *\/ } (async () =&gt; { [nacl, scrypt] = await Promise.all([new Promise(nacl_factory.instantiate), new Promise(scrypt_module_factory)]); return main(); })();<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[75,40],"class_list":["post-1346","post","type-post","status-publish","format-standard","hentry","category-howto","tag-asynchronous","tag-javascript"],"_links":{"self":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/1346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/comments?post=1346"}],"version-history":[{"count":4,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/1346\/revisions"}],"predecessor-version":[{"id":1351,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/1346\/revisions\/1351"}],"wp:attachment":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/media?parent=1346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/categories?post=1346"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/tags?post=1346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}