Created
November 22, 2019 16:35
-
-
Save miquelbeltran/3c05eea33346f28794f28d7665e5e77c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Did you add the onError to the listen() method? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
StreamSubscription streamWithError(Stream<String> stream) { | |
return stream.listen((_) {} /* finish this method */); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StreamSubscription streamWithError(Stream<String> stream) { | |
return stream.listen((_) {}, onError: (error) {}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() async { | |
var hadError = false; | |
// catch unhandled onError | |
runZoned(() { | |
// ignore: close_sinks | |
final streamController = StreamController<String>(sync: true); | |
// ignore: cancel_subscriptions | |
final subscription = streamWithError(streamController.stream); | |
if (subscription == null) { | |
_result( | |
false, ['Something went wrong! The stream subscription is missing.']); | |
hadError = true; | |
return; | |
} | |
streamController.addError("ERROR!"); | |
}, onError: (e, stackTrace) { | |
_result(false, | |
['Something went wrong! Looks like the error was not processed.']); | |
hadError = true; | |
}); | |
if (!hadError) { | |
_result(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment