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
webmidi
backend, the browser requires async initialization for theMidiInput
andMidiOutput
objects. When usingMidiInput::new
andMidiOutput::new
and then immediately querying the ports, none will be available until the call torequestMidiAccess
resolves.In the existing
browser
example, 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_async
methods to bothMidiInput
andMidiOutput
new
method in all backends except forwebmidi
test_play
example to test outputindex.html
due to browser support of JS modulesread_input_async
exampleNotes
new_async
methods could be put behind a feature flag (there's an added dependency in thewebmidi
case 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!