Last active
November 22, 2019 18:00
-
-
Save miquelbeltran/38d259d6fbfa8891bfeb3b5c76033ddb 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 try to use stream.first? | |
Did you try returning "Top User is: $name"? | |
Did you try to use future.asStream()? | |
Check the classes Stream and Future for the method specifications. |
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
Future<String> topUser(Stream<String> stream) async { | |
// implement this method | |
} | |
Stream<String> usernameAsStream(Future<String> username) { | |
// implement 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
Future<String> topUser(Stream<String> stream) async { | |
var user = await stream.first; | |
return 'Top User is: $user'; | |
} | |
Stream<String> usernameAsStream(Future<String> username) { | |
return username.asStream(); | |
} |
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 { | |
try { | |
final stream = Stream.fromIterable(['First', 'Second']); | |
final value = await topUser(stream); | |
if (value != 'Top User is: First') { | |
_result(false, | |
['Something went wrong! The result of `topUser` is incorrect.']); | |
return; | |
} | |
} catch (error) { | |
_result(false, [ | |
'Something went wrong! Tried calling `firstEvent` but got exception: $error' | |
]); | |
return; | |
} | |
try { | |
final value = await usernameAsStream(Future.value('First')).single; | |
if (value != 'First') { | |
_result(false, [ | |
'Something went wrong! The result of `usernameAsStream` is incorrect.' | |
]); | |
return; | |
} | |
} catch (error) { | |
_result(false, [ | |
'Something went wrong! Tried calling `usernameAsStream` but got exception: $error' | |
]); | |
return; | |
} | |
_result(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment