createMapping method
Implementation
Future<void> createMapping(
MidiMapping mapping,
) async {
final response = websocket.stream
.where((event) => event is MidiCreateResponse)
.map((event) => event as MidiCreateResponse)
.map(
(event) => event.mapping,
)
.where((event) => event.mapping == mapping)
.timeout(responseTimeout)
.first;
// FIXME: optimistically add the mapping to the UI state
/*
__mappings[mapping.id] = mapping.mapping;
notifyListeners();
*/
final message = MidiApiMessage.createRequest(mapping: mapping);
websocket.sink.add(message);
try {
final responseMapping = await response;
__mappings[responseMapping.id] = responseMapping.mapping;
notifyListeners();
} on TimeoutException {
// FIXME: rollback optimistic update
/*
__mappings.remove(mapping.id);
notifyListeners();
*/
}
}