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
// asynchronous data | |
main() async { | |
Duration interval = Duration(seconds: 1); | |
Stream<int> stream = Stream<int>.periodic(interval,transform); | |
stream = stream.take(10); | |
stream = stream.skipWhile(condition); | |
await for(int i in stream){ | |
print(i); | |
} | |
} |
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
// asynchronous data | |
main() async { | |
Duration interval = Duration(seconds: 1); | |
Stream<int> stream = Stream<int>.periodic(interval,transform); | |
stream = stream.take(10); | |
stream = stream.skip(2); | |
await for(int i in stream){ | |
print(i); | |
} | |
} |
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
// asynchronous data | |
main() async { | |
Duration interval = Duration(seconds: 1); | |
Stream<int> stream = Stream<int>.periodic(interval,transform); | |
// Added this statement | |
stream = stream.takeWhile(condition); | |
await for(int i in stream){ | |
print(i); | |
} | |
} |
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
// asynchronous data | |
main() async { | |
Duration interval = Duration(seconds: 1); | |
Stream<int> stream = Stream<int>.periodic(interval,transform); | |
// Added this statement | |
stream = stream.take(5); | |
await for(int i in stream){ | |
print(i); | |
} | |
} |
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
// asynchronous data | |
main() async { | |
Duration interval = Duration(seconds: 2); | |
Stream<int> stream = Stream<int>.periodic(interval, callback); | |
await for(int i in stream){ | |
print(i); | |
} | |
} | |
// This callback modify the given value to even number. | |
int callback(int value){ |
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'; | |
Future<int> sumStream(Stream<int> stream) async { | |
var sum = 0; | |
try { | |
await for (var value in stream) { | |
sum += value; | |
} | |
} catch (e) { | |
return -1; |
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'; | |
Future<int> sumStream(Stream<int> stream) async { | |
var sum = 0; | |
await for (var value in stream) { | |
sum += value; | |
} | |
return sum; | |
} | |
Stream<int> countStream(int to) async* { |
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'; | |
var stream = Stream.fromIterable([1, 2, 3, 4, 5]); | |
void main() { | |
final controller1 = new StreamController(); | |
final controller2 = new StreamController(); | |
controller1.addStream(stream); |
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'; | |
void main() { | |
var streamController = StreamController(); | |
streamController.stream.listen(print); | |
//streamController.stream.listen(print); // ошибка: поток уже слушается, разкомментируйте строку, чтобы увидеть | |
streamController.sink.add('Одиночная подписка: 1'); | |
streamController.sink.add('Одиночная подписка: 2'); | |
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'; | |
void main() { | |
var controller = StreamController<num>(); | |
// Create StreamTransformer with transformer closure | |
var streamTransformer = StreamTransformer<num, num>.fromHandlers( | |
handleData: (num data, EventSink sink) { | |
sink.add(data * 2); | |
}, |