rocketryjs / plugin-web-midi

🔌🛠 Plugin for Rocketry that enables Web MIDI support
MIT License
1 stars 0 forks source link

Initialize using top-level await #1

Open evelynhathaway opened 5 years ago

evelynhathaway commented 5 years ago

I think it would be good to have a submodule that uses top-level await to halt code execution until the user or user agent accepts the Web MIDI API permission. I think it would be a bad idea to do this on the main module since it could be blocked for minutes.

Currently, the proposal for top-level await is at stage 2 and I don't know when/if support will come to Node.js.

Possible example of a wrapper that could use top level await to simplify implementation `@rocketry/plugin-web-midi/sync` ```js import pluginWebMidi, {init} from "./index"; await init(); // will use default options export default pluginWebMidi; export * from "./index"; ``` --- `comsumer.js` ```js import "@rocketry/plugin-web-midi/sync"; import rocketry from "@rocketry/core"; // Use Rocketry here without having to worry about making an async context // Nothing past the last import will run until the permissions have been accepted/rejected ```
evelynhathaway commented 4 years ago

Looks like top-level await will experimental soon.