Async constructors for MidiInput and MidiOutput to support WebMIDI #164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates a bit to #47 and #48
Motivation
When using the
webmidibackend, the browser requires async initialization for theMidiInputandMidiOutputobjects. When usingMidiInput::newandMidiOutput::newand then immediately querying the ports, none will be available until the call torequestMidiAccessresolves.In the existing
browserexample, a loop is set up to poll until devices are available, but this makes it difficult to distinguish between the case where there are actually no devices, or if they just haven't resolved yet.Changes
new_asyncmethods to bothMidiInputandMidiOutputnewmethod in all backends except forwebmiditest_playexample to test outputindex.htmldue to browser support of JS modulesread_input_asyncexampleNotes
new_asyncmethods could be put behind a feature flag (there's an added dependency in thewebmidicase forwasm_bindgen_futures, however I believe most people would find the async version more usable than the sync version when targeting the web. Would love to hear what others think about this.Let me know if you have any questions or suggested changes. Thanks for the awesome work on this crate!