| OLD | NEW |
| (Empty) |
| 1 part of dart.async; | |
| 2 abstract class Stream<T> {Stream(); | |
| 3 factory Stream.fromFuture(Future<T> future) { | |
| 4 _StreamController<T> controller = ((__x19) => DEVC$RT.cast(__x19, DEVC$RT.type
((StreamController<T> _) { | |
| 5 } | |
| 6 ), DEVC$RT.type((_StreamController<T> _) { | |
| 7 } | |
| 8 ), "CastUser", """line 88, column 9 of dart:async/stream.dart: """, __x19 is _
StreamController<T>, false))(new StreamController<T>(sync: true)); | |
| 9 future.then((value) { | |
| 10 controller._add(DEVC$RT.cast(value, dynamic, T, "CompositeCast", """line 90,
column 25 of dart:async/stream.dart: """, value is T, false)); | |
| 11 controller._closeUnchecked(); | |
| 12 } | |
| 13 , onError: (error, stackTrace) { | |
| 14 controller._addError(error, DEVC$RT.cast(stackTrace, dynamic, StackTrace, "D
ynamicCast", """line 94, column 37 of dart:async/stream.dart: """, stackTrace is
StackTrace, true)); | |
| 15 controller._closeUnchecked(); | |
| 16 } | |
| 17 ); | |
| 18 return controller.stream; | |
| 19 } | |
| 20 factory Stream.fromIterable(Iterable<T> data) { | |
| 21 return new _GeneratedStreamImpl<T>(() => new _IterablePendingEvents<T>(data)); | |
| 22 } | |
| 23 factory Stream.periodic(Duration period, [T computation(int computationCount)])
{ | |
| 24 if (computation == null) computation = ((i) => null); | |
| 25 Timer timer; | |
| 26 int computationCount = 0; | |
| 27 StreamController<T> controller; | |
| 28 Stopwatch watch = new Stopwatch(); | |
| 29 void sendEvent() { | |
| 30 watch.reset(); | |
| 31 T data = computation(computationCount++); | |
| 32 controller.add(data); | |
| 33 } | |
| 34 void startPeriodicTimer() { | |
| 35 assert (timer == null); timer = new Timer.periodic(period, (Timer timer) { | |
| 36 sendEvent(); | |
| 37 } | |
| 38 ); | |
| 39 } | |
| 40 controller = new StreamController<T>(sync: true, onListen: () { | |
| 41 watch.start(); | |
| 42 startPeriodicTimer(); | |
| 43 } | |
| 44 , onPause: () { | |
| 45 timer.cancel(); | |
| 46 timer = null; | |
| 47 watch.stop(); | |
| 48 } | |
| 49 , onResume: () { | |
| 50 assert (timer == null); Duration elapsed = watch.elapsed; | |
| 51 watch.start(); | |
| 52 timer = new Timer(period - elapsed, () { | |
| 53 timer = null; | |
| 54 startPeriodicTimer(); | |
| 55 sendEvent(); | |
| 56 } | |
| 57 ); | |
| 58 } | |
| 59 , onCancel: () { | |
| 60 if (timer != null) timer.cancel(); | |
| 61 timer = null; | |
| 62 } | |
| 63 ); | |
| 64 return controller.stream; | |
| 65 } | |
| 66 factory Stream.eventTransformed(Stream source, EventSink mapSink(EventSink<T> s
ink)) { | |
| 67 return new _BoundSinkStream<dynamic, T>(source, DEVC$RT.cast(mapSink, DEVC$RT.
type((__CastType20<T> _) { | |
| 68 } | |
| 69 ), DEVC$RT.type((_SinkMapper<dynamic, dynamic> _) { | |
| 70 } | |
| 71 ), "CompositeCast", """line 217, column 41 of dart:async/stream.dart: """, map
Sink is _SinkMapper<dynamic, dynamic>, false)); | |
| 72 } | |
| 73 bool get isBroadcast => false; | |
| 74 Stream<T> asBroadcastStream({ | |
| 75 void onListen(StreamSubscription<T> subscription), void onCancel(StreamSubscri
ption<T> subscription)} | |
| 76 ) { | |
| 77 return new _AsBroadcastStream<T>(this, DEVC$RT.cast(onListen, DEVC$RT.type((__
CastType24<T> _) { | |
| 78 } | |
| 79 ), __CastType22, "CompositeCast", """line 249, column 44 of dart:async/stream.
dart: """, onListen is __CastType22, false), DEVC$RT.cast(onCancel, DEVC$RT.type
((__CastType24<T> _) { | |
| 80 } | |
| 81 ), __CastType22, "CompositeCast", """line 249, column 54 of dart:async/stream.
dart: """, onCancel is __CastType22, false)); | |
| 82 } | |
| 83 StreamSubscription<T> listen(void onData(T event), { | |
| 84 Function onError, void onDone(), bool cancelOnError} | |
| 85 ); | |
| 86 Stream<T> where(bool test(T event)) { | |
| 87 return new _WhereStream<T>(this, test); | |
| 88 } | |
| 89 Stream map(convert(T event)) { | |
| 90 return new _MapStream<T, dynamic>(this, convert); | |
| 91 } | |
| 92 Stream asyncMap(convert(T event)) { | |
| 93 StreamController controller; | |
| 94 StreamSubscription subscription; | |
| 95 void onListen() { | |
| 96 final add = controller.add; | |
| 97 assert (controller is _StreamController || controller is _BroadcastStreamCo
ntroller); final eventSink = controller; | |
| 98 final addError = eventSink._addError; | |
| 99 subscription = this.listen((T event) { | |
| 100 var newValue; | |
| 101 try { | |
| 102 newValue = convert(event); | |
| 103 } | |
| 104 catch (e, s) { | |
| 105 controller.addError(e, s); | |
| 106 return;} | |
| 107 if (newValue is Future) { | |
| 108 subscription.pause(); | |
| 109 newValue.then(add, onError: addError).whenComplete(subscription.resume)
; | |
| 110 } | |
| 111 else { | |
| 112 controller.add(newValue); | |
| 113 } | |
| 114 } | |
| 115 , onError: DEVC$RT.cast(addError, dynamic, Function, "DynamicCast", """line
339, column 20 of dart:async/stream.dart: """, addError is Function, true), onDo
ne: controller.close); | |
| 116 } | |
| 117 if (this.isBroadcast) { | |
| 118 controller = new StreamController.broadcast(onListen: onListen, onCancel: ()
{ | |
| 119 subscription.cancel(); | |
| 120 } | |
| 121 , sync: true); | |
| 122 } | |
| 123 else { | |
| 124 controller = new StreamController(onListen: onListen, onPause: () { | |
| 125 subscription.pause(); | |
| 126 } | |
| 127 , onResume: () { | |
| 128 subscription.resume(); | |
| 129 } | |
| 130 , onCancel: () { | |
| 131 subscription.cancel(); | |
| 132 } | |
| 133 , sync: true); | |
| 134 } | |
| 135 return controller.stream; | |
| 136 } | |
| 137 Stream asyncExpand(Stream convert(T event)) { | |
| 138 StreamController controller; | |
| 139 StreamSubscription subscription; | |
| 140 void onListen() { | |
| 141 assert (controller is _StreamController || controller is _BroadcastStreamCon
troller); final eventSink = controller; | |
| 142 subscription = this.listen((T event) { | |
| 143 Stream newStream; | |
| 144 try { | |
| 145 newStream = convert(event); | |
| 146 } | |
| 147 catch (e, s) { | |
| 148 controller.addError(e, s); | |
| 149 return;} | |
| 150 if (newStream != null) { | |
| 151 subscription.pause(); | |
| 152 controller.addStream(newStream).whenComplete(subscription.resume); | |
| 153 } | |
| 154 } | |
| 155 , onError: DEVC$RT.cast(eventSink._addError, dynamic, Function, "DynamicCast
", """line 396, column 20 of dart:async/stream.dart: """, eventSink._addError is
Function, true), onDone: controller.close); | |
| 156 } | |
| 157 if (this.isBroadcast) { | |
| 158 controller = new StreamController.broadcast(onListen: onListen, onCancel: ()
{ | |
| 159 subscription.cancel(); | |
| 160 } | |
| 161 , sync: true); | |
| 162 } | |
| 163 else { | |
| 164 controller = new StreamController(onListen: onListen, onPause: () { | |
| 165 subscription.pause(); | |
| 166 } | |
| 167 , onResume: () { | |
| 168 subscription.resume(); | |
| 169 } | |
| 170 , onCancel: () { | |
| 171 subscription.cancel(); | |
| 172 } | |
| 173 , sync: true); | |
| 174 } | |
| 175 return controller.stream; | |
| 176 } | |
| 177 Stream<T> handleError(Function onError, { | |
| 178 bool test(error)} | |
| 179 ) { | |
| 180 return new _HandleErrorStream<T>(this, onError, test); | |
| 181 } | |
| 182 Stream expand(Iterable convert(T value)) { | |
| 183 return new _ExpandStream<T, dynamic>(this, convert); | |
| 184 } | |
| 185 Future pipe(StreamConsumer<T> streamConsumer) { | |
| 186 return streamConsumer.addStream(this).then((_) => streamConsumer.close()); | |
| 187 } | |
| 188 Stream transform(StreamTransformer<T, dynamic> streamTransformer) { | |
| 189 return streamTransformer.bind(this); | |
| 190 } | |
| 191 Future<T> reduce(T combine(T previous, T element)) { | |
| 192 _Future<T> result = new _Future<T>(); | |
| 193 bool seenFirst = false; | |
| 194 T value; | |
| 195 StreamSubscription subscription; | |
| 196 subscription = this.listen((T element) { | |
| 197 if (seenFirst) { | |
| 198 _runUserCode(() => combine(value, element), (T newValue) { | |
| 199 value = newValue; | |
| 200 } | |
| 201 , ((__x29) => DEVC$RT.cast(__x29, dynamic, __CastType26, "CompositeCast",
"""line 502, column 24 of dart:async/stream.dart: """, __x29 is __CastType26, fa
lse))(_cancelAndErrorClosure(subscription, result))); | |
| 202 } | |
| 203 else { | |
| 204 value = element; | |
| 205 seenFirst = true; | |
| 206 } | |
| 207 } | |
| 208 , onError: result._completeError, onDone: () { | |
| 209 if (!seenFirst) { | |
| 210 try { | |
| 211 throw IterableElementError.noElement(); | |
| 212 } | |
| 213 catch (e, s) { | |
| 214 _completeWithErrorCallback(result, e, s); | |
| 215 } | |
| 216 } | |
| 217 else { | |
| 218 result._complete(value); | |
| 219 } | |
| 220 } | |
| 221 , cancelOnError: true); | |
| 222 return result; | |
| 223 } | |
| 224 Future fold(var initialValue, combine(var previous, T element)) { | |
| 225 _Future result = new _Future(); | |
| 226 var value = initialValue; | |
| 227 StreamSubscription subscription; | |
| 228 subscription = this.listen((T element) { | |
| 229 _runUserCode(() => combine(value, element), (newValue) { | |
| 230 value = newValue; | |
| 231 } | |
| 232 , ((__x30) => DEVC$RT.cast(__x30, dynamic, __CastType26, "CompositeCast", ""
"line 535, column 11 of dart:async/stream.dart: """, __x30 is __CastType26, fals
e))(_cancelAndErrorClosure(subscription, result))); | |
| 233 } | |
| 234 , onError: (e, st) { | |
| 235 result._completeError(e, DEVC$RT.cast(st, dynamic, StackTrace, "DynamicCast"
, """line 539, column 34 of dart:async/stream.dart: """, st is StackTrace, true)
); | |
| 236 } | |
| 237 , onDone: () { | |
| 238 result._complete(value); | |
| 239 } | |
| 240 , cancelOnError: true); | |
| 241 return result; | |
| 242 } | |
| 243 Future<String> join([String separator = ""]) { | |
| 244 _Future<String> result = new _Future<String>(); | |
| 245 StringBuffer buffer = new StringBuffer(); | |
| 246 StreamSubscription subscription; | |
| 247 bool first = true; | |
| 248 subscription = this.listen((T element) { | |
| 249 if (!first) { | |
| 250 buffer.write(separator); | |
| 251 } | |
| 252 first = false; | |
| 253 try { | |
| 254 buffer.write(element); | |
| 255 } | |
| 256 catch (e, s) { | |
| 257 _cancelAndErrorWithReplacement(subscription, result, e, s); | |
| 258 } | |
| 259 } | |
| 260 , onError: (e) { | |
| 261 result._completeError(e); | |
| 262 } | |
| 263 , onDone: () { | |
| 264 result._complete(buffer.toString()); | |
| 265 } | |
| 266 , cancelOnError: true); | |
| 267 return result; | |
| 268 } | |
| 269 Future<bool> contains(Object needle) { | |
| 270 _Future<bool> future = new _Future<bool>(); | |
| 271 StreamSubscription subscription; | |
| 272 subscription = this.listen((T element) { | |
| 273 _runUserCode(() => (element == needle), (bool isMatch) { | |
| 274 if (isMatch) { | |
| 275 _cancelAndValue(subscription, future, true); | |
| 276 } | |
| 277 } | |
| 278 , ((__x31) => DEVC$RT.cast(__x31, dynamic, __CastType26, "CompositeCast", ""
"line 603, column 13 of dart:async/stream.dart: """, __x31 is __CastType26, fals
e))(_cancelAndErrorClosure(subscription, future))); | |
| 279 } | |
| 280 , onError: future._completeError, onDone: () { | |
| 281 future._complete(false); | |
| 282 } | |
| 283 , cancelOnError: true); | |
| 284 return future; | |
| 285 } | |
| 286 Future forEach(void action(T element)) { | |
| 287 _Future future = new _Future(); | |
| 288 StreamSubscription subscription; | |
| 289 subscription = this.listen((T element) { | |
| 290 _runUserCode(() => action(element), (_) { | |
| 291 } | |
| 292 , ((__x32) => DEVC$RT.cast(__x32, dynamic, __CastType26, "CompositeCast", ""
"line 629, column 13 of dart:async/stream.dart: """, __x32 is __CastType26, fals
e))(_cancelAndErrorClosure(subscription, future))); | |
| 293 } | |
| 294 , onError: future._completeError, onDone: () { | |
| 295 future._complete(null); | |
| 296 } | |
| 297 , cancelOnError: true); | |
| 298 return future; | |
| 299 } | |
| 300 Future<bool> every(bool test(T element)) { | |
| 301 _Future<bool> future = new _Future<bool>(); | |
| 302 StreamSubscription subscription; | |
| 303 subscription = this.listen((T element) { | |
| 304 _runUserCode(() => test(element), (bool isMatch) { | |
| 305 if (!isMatch) { | |
| 306 _cancelAndValue(subscription, future, false); | |
| 307 } | |
| 308 } | |
| 309 , ((__x33) => DEVC$RT.cast(__x33, dynamic, __CastType26, "CompositeCast", ""
"line 658, column 13 of dart:async/stream.dart: """, __x33 is __CastType26, fals
e))(_cancelAndErrorClosure(subscription, future))); | |
| 310 } | |
| 311 , onError: future._completeError, onDone: () { | |
| 312 future._complete(true); | |
| 313 } | |
| 314 , cancelOnError: true); | |
| 315 return future; | |
| 316 } | |
| 317 Future<bool> any(bool test(T element)) { | |
| 318 _Future<bool> future = new _Future<bool>(); | |
| 319 StreamSubscription subscription; | |
| 320 subscription = this.listen((T element) { | |
| 321 _runUserCode(() => test(element), (bool isMatch) { | |
| 322 if (isMatch) { | |
| 323 _cancelAndValue(subscription, future, true); | |
| 324 } | |
| 325 } | |
| 326 , ((__x34) => DEVC$RT.cast(__x34, dynamic, __CastType26, "CompositeCast", ""
"line 695, column 13 of dart:async/stream.dart: """, __x34 is __CastType26, fals
e))(_cancelAndErrorClosure(subscription, future))); | |
| 327 } | |
| 328 , onError: future._completeError, onDone: () { | |
| 329 future._complete(false); | |
| 330 } | |
| 331 , cancelOnError: true); | |
| 332 return future; | |
| 333 } | |
| 334 Future<int> get length { | |
| 335 _Future<int> future = new _Future<int>(); | |
| 336 int count = 0; | |
| 337 this.listen((_) { | |
| 338 count++; | |
| 339 } | |
| 340 , onError: future._completeError, onDone: () { | |
| 341 future._complete(count); | |
| 342 } | |
| 343 , cancelOnError: true); | |
| 344 return future; | |
| 345 } | |
| 346 Future<bool> get isEmpty { | |
| 347 _Future<bool> future = new _Future<bool>(); | |
| 348 StreamSubscription subscription; | |
| 349 subscription = this.listen((_) { | |
| 350 _cancelAndValue(subscription, future, false); | |
| 351 } | |
| 352 , onError: future._completeError, onDone: () { | |
| 353 future._complete(true); | |
| 354 } | |
| 355 , cancelOnError: true); | |
| 356 return future; | |
| 357 } | |
| 358 Future<List<T>> toList() { | |
| 359 List<T> result = <T> []; | |
| 360 _Future<List<T>> future = new _Future<List<T>>(); | |
| 361 this.listen((T data) { | |
| 362 result.add(data); | |
| 363 } | |
| 364 , onError: future._completeError, onDone: () { | |
| 365 future._complete(result); | |
| 366 } | |
| 367 , cancelOnError: true); | |
| 368 return future; | |
| 369 } | |
| 370 Future<Set<T>> toSet() { | |
| 371 Set<T> result = new Set<T>(); | |
| 372 _Future<Set<T>> future = new _Future<Set<T>>(); | |
| 373 this.listen((T data) { | |
| 374 result.add(data); | |
| 375 } | |
| 376 , onError: future._completeError, onDone: () { | |
| 377 future._complete(result); | |
| 378 } | |
| 379 , cancelOnError: true); | |
| 380 return future; | |
| 381 } | |
| 382 Future drain([var futureValue]) => listen(null, cancelOnError: true).asFuture(f
utureValue); | |
| 383 Stream<T> take(int count) { | |
| 384 return new _TakeStream<T>(this, count); | |
| 385 } | |
| 386 Stream<T> takeWhile(bool test(T element)) { | |
| 387 return new _TakeWhileStream<T>(this, test); | |
| 388 } | |
| 389 Stream<T> skip(int count) { | |
| 390 return new _SkipStream<T>(this, count); | |
| 391 } | |
| 392 Stream<T> skipWhile(bool test(T element)) { | |
| 393 return new _SkipWhileStream<T>(this, test); | |
| 394 } | |
| 395 Stream<T> distinct([bool equals(T previous, T next)]) { | |
| 396 return new _DistinctStream<T>(this, equals); | |
| 397 } | |
| 398 Future<T> get first { | |
| 399 _Future<T> future = new _Future<T>(); | |
| 400 StreamSubscription subscription; | |
| 401 subscription = this.listen((T value) { | |
| 402 _cancelAndValue(subscription, future, value); | |
| 403 } | |
| 404 , onError: future._completeError, onDone: () { | |
| 405 try { | |
| 406 throw IterableElementError.noElement(); | |
| 407 } | |
| 408 catch (e, s) { | |
| 409 _completeWithErrorCallback(future, e, s); | |
| 410 } | |
| 411 } | |
| 412 , cancelOnError: true); | |
| 413 return future; | |
| 414 } | |
| 415 Future<T> get last { | |
| 416 _Future<T> future = new _Future<T>(); | |
| 417 T result = null; | |
| 418 bool foundResult = false; | |
| 419 StreamSubscription subscription; | |
| 420 subscription = this.listen((T value) { | |
| 421 foundResult = true; | |
| 422 result = value; | |
| 423 } | |
| 424 , onError: future._completeError, onDone: () { | |
| 425 if (foundResult) { | |
| 426 future._complete(result); | |
| 427 return;} | |
| 428 try { | |
| 429 throw IterableElementError.noElement(); | |
| 430 } | |
| 431 catch (e, s) { | |
| 432 _completeWithErrorCallback(future, e, s); | |
| 433 } | |
| 434 } | |
| 435 , cancelOnError: true); | |
| 436 return future; | |
| 437 } | |
| 438 Future<T> get single { | |
| 439 _Future<T> future = new _Future<T>(); | |
| 440 T result = null; | |
| 441 bool foundResult = false; | |
| 442 StreamSubscription subscription; | |
| 443 subscription = this.listen((T value) { | |
| 444 if (foundResult) { | |
| 445 try { | |
| 446 throw IterableElementError.tooMany(); | |
| 447 } | |
| 448 catch (e, s) { | |
| 449 _cancelAndErrorWithReplacement(subscription, future, e, s); | |
| 450 } | |
| 451 return;} | |
| 452 foundResult = true; | |
| 453 result = value; | |
| 454 } | |
| 455 , onError: future._completeError, onDone: () { | |
| 456 if (foundResult) { | |
| 457 future._complete(result); | |
| 458 return;} | |
| 459 try { | |
| 460 throw IterableElementError.noElement(); | |
| 461 } | |
| 462 catch (e, s) { | |
| 463 _completeWithErrorCallback(future, e, s); | |
| 464 } | |
| 465 } | |
| 466 , cancelOnError: true); | |
| 467 return future; | |
| 468 } | |
| 469 Future<dynamic> firstWhere(bool test(T element), { | |
| 470 Object defaultValue()} | |
| 471 ) { | |
| 472 _Future<dynamic> future = new _Future(); | |
| 473 StreamSubscription subscription; | |
| 474 subscription = this.listen((T value) { | |
| 475 _runUserCode(() => test(value), (bool isMatch) { | |
| 476 if (isMatch) { | |
| 477 _cancelAndValue(subscription, future, value); | |
| 478 } | |
| 479 } | |
| 480 , ((__x35) => DEVC$RT.cast(__x35, dynamic, __CastType26, "CompositeCast", ""
"line 1037, column 11 of dart:async/stream.dart: """, __x35 is __CastType26, fal
se))(_cancelAndErrorClosure(subscription, future))); | |
| 481 } | |
| 482 , onError: future._completeError, onDone: () { | |
| 483 if (defaultValue != null) { | |
| 484 _runUserCode(defaultValue, future._complete, future._completeError); | |
| 485 return;} | |
| 486 try { | |
| 487 throw IterableElementError.noElement(); | |
| 488 } | |
| 489 catch (e, s) { | |
| 490 _completeWithErrorCallback(future, e, s); | |
| 491 } | |
| 492 } | |
| 493 , cancelOnError: true); | |
| 494 return future; | |
| 495 } | |
| 496 Future<dynamic> lastWhere(bool test(T element), { | |
| 497 Object defaultValue()} | |
| 498 ) { | |
| 499 _Future<dynamic> future = new _Future(); | |
| 500 T result = null; | |
| 501 bool foundResult = false; | |
| 502 StreamSubscription subscription; | |
| 503 subscription = this.listen((T value) { | |
| 504 _runUserCode(() => true == test(value), (bool isMatch) { | |
| 505 if (isMatch) { | |
| 506 foundResult = true; | |
| 507 result = value; | |
| 508 } | |
| 509 } | |
| 510 , ((__x36) => DEVC$RT.cast(__x36, dynamic, __CastType26, "CompositeCast", ""
"line 1078, column 11 of dart:async/stream.dart: """, __x36 is __CastType26, fal
se))(_cancelAndErrorClosure(subscription, future))); | |
| 511 } | |
| 512 , onError: future._completeError, onDone: () { | |
| 513 if (foundResult) { | |
| 514 future._complete(result); | |
| 515 return;} | |
| 516 if (defaultValue != null) { | |
| 517 _runUserCode(defaultValue, future._complete, future._completeError); | |
| 518 return;} | |
| 519 try { | |
| 520 throw IterableElementError.noElement(); | |
| 521 } | |
| 522 catch (e, s) { | |
| 523 _completeWithErrorCallback(future, e, s); | |
| 524 } | |
| 525 } | |
| 526 , cancelOnError: true); | |
| 527 return future; | |
| 528 } | |
| 529 Future<T> singleWhere(bool test(T element)) { | |
| 530 _Future<T> future = new _Future<T>(); | |
| 531 T result = null; | |
| 532 bool foundResult = false; | |
| 533 StreamSubscription subscription; | |
| 534 subscription = this.listen((T value) { | |
| 535 _runUserCode(() => true == test(value), (bool isMatch) { | |
| 536 if (isMatch) { | |
| 537 if (foundResult) { | |
| 538 try { | |
| 539 throw IterableElementError.tooMany(); | |
| 540 } | |
| 541 catch (e, s) { | |
| 542 _cancelAndErrorWithReplacement(subscription, future, e, s); | |
| 543 } | |
| 544 return;} | |
| 545 foundResult = true; | |
| 546 result = value; | |
| 547 } | |
| 548 } | |
| 549 , ((__x37) => DEVC$RT.cast(__x37, dynamic, __CastType26, "CompositeCast", ""
"line 1130, column 11 of dart:async/stream.dart: """, __x37 is __CastType26, fal
se))(_cancelAndErrorClosure(subscription, future))); | |
| 550 } | |
| 551 , onError: future._completeError, onDone: () { | |
| 552 if (foundResult) { | |
| 553 future._complete(result); | |
| 554 return;} | |
| 555 try { | |
| 556 throw IterableElementError.noElement(); | |
| 557 } | |
| 558 catch (e, s) { | |
| 559 _completeWithErrorCallback(future, e, s); | |
| 560 } | |
| 561 } | |
| 562 , cancelOnError: true); | |
| 563 return future; | |
| 564 } | |
| 565 Future<T> elementAt(int index) { | |
| 566 if (index is! int || index < 0) throw new ArgumentError(index); | |
| 567 _Future<T> future = new _Future<T>(); | |
| 568 StreamSubscription subscription; | |
| 569 int elementIndex = 0; | |
| 570 subscription = this.listen((T value) { | |
| 571 if (index == elementIndex) { | |
| 572 _cancelAndValue(subscription, future, value); | |
| 573 return;} | |
| 574 elementIndex += 1; | |
| 575 } | |
| 576 , onError: future._completeError, onDone: () { | |
| 577 future._completeError(new RangeError.index(index, this, "index", null, eleme
ntIndex)); | |
| 578 } | |
| 579 , cancelOnError: true); | |
| 580 return future; | |
| 581 } | |
| 582 Stream timeout(Duration timeLimit, { | |
| 583 void onTimeout(EventSink sink)} | |
| 584 ) { | |
| 585 StreamController controller; | |
| 586 StreamSubscription<T> subscription; | |
| 587 Timer timer; | |
| 588 Zone zone; | |
| 589 Function timeout; | |
| 590 void onData(T event) { | |
| 591 timer.cancel(); | |
| 592 controller.add(event); | |
| 593 timer = zone.createTimer(timeLimit, DEVC$RT.cast(timeout, Function, __CastT
ype38, "CompositeCast", """line 1220, column 43 of dart:async/stream.dart: """,
timeout is __CastType38, false)); | |
| 594 } | |
| 595 void onError(error, StackTrace stackTrace) { | |
| 596 timer.cancel(); | |
| 597 assert (controller is _StreamController || controller is _BroadcastStreamCo
ntroller); var eventSink = controller; | |
| 598 eventSink._addError(error, stackTrace); | |
| 599 timer = zone.createTimer(timeLimit, DEVC$RT.cast(timeout, Function, __CastT
ype38, "CompositeCast", """line 1228, column 43 of dart:async/stream.dart: """,
timeout is __CastType38, false)); | |
| 600 } | |
| 601 void onDone() { | |
| 602 timer.cancel(); | |
| 603 controller.close(); | |
| 604 } | |
| 605 void onListen() { | |
| 606 zone = Zone.current; | |
| 607 if (onTimeout == null) { | |
| 608 timeout = () { | |
| 609 controller.addError(new TimeoutException("No stream event", timeLimit),
null); | |
| 610 } | |
| 611 ; | |
| 612 } | |
| 613 else { | |
| 614 onTimeout = ((__x41) => DEVC$RT.cast(__x41, ZoneUnaryCallback, __CastType3
9, "CompositeCast", """line 1246, column 21 of dart:async/stream.dart: """, __x4
1 is __CastType39, false))(zone.registerUnaryCallback(onTimeout)); | |
| 615 _ControllerEventSinkWrapper wrapper = new _ControllerEventSinkWrapper(nul
l); | |
| 616 timeout = () { | |
| 617 wrapper._sink = controller; | |
| 618 zone.runUnaryGuarded(onTimeout, wrapper); | |
| 619 wrapper._sink = null; | |
| 620 } | |
| 621 ; | |
| 622 } | |
| 623 subscription = this.listen(onData, onError: onError, onDone: onDone); | |
| 624 timer = zone.createTimer(timeLimit, DEVC$RT.cast(timeout, Function, __CastT
ype38, "CompositeCast", """line 1257, column 43 of dart:async/stream.dart: """,
timeout is __CastType38, false)); | |
| 625 } | |
| 626 Future onCancel() { | |
| 627 timer.cancel(); | |
| 628 Future result = subscription.cancel(); | |
| 629 subscription = null; | |
| 630 return result; | |
| 631 } | |
| 632 controller = isBroadcast ? new _SyncBroadcastStreamController(onListen, onCan
cel) : new _SyncStreamController(onListen, () { | |
| 633 timer.cancel(); | |
| 634 subscription.pause(); | |
| 635 } | |
| 636 , () { | |
| 637 subscription.resume(); | |
| 638 timer = zone.createTimer(timeLimit, DEVC$RT.cast(timeout, Function, __CastT
ype38, "CompositeCast", """line 1276, column 53 of dart:async/stream.dart: """,
timeout is __CastType38, false)); | |
| 639 } | |
| 640 , onCancel); | |
| 641 return controller.stream; | |
| 642 } | |
| 643 } | |
| 644 abstract class StreamSubscription<T> {Future cancel(); | |
| 645 void onData(void handleData(T data)); | |
| 646 void onError(Function handleError); | |
| 647 void onDone(void handleDone()); | |
| 648 void pause([Future resumeSignal]); | |
| 649 void resume(); | |
| 650 bool get isPaused; | |
| 651 Future asFuture([var futureValue]); | |
| 652 } | |
| 653 abstract class EventSink<T> implements Sink<T> {void add(T event); | |
| 654 void addError(errorEvent, [StackTrace stackTrace]); | |
| 655 void close(); | |
| 656 } | |
| 657 class StreamView<T> extends Stream<T> {Stream<T> _stream; | |
| 658 StreamView(this._stream); | |
| 659 bool get isBroadcast => _stream.isBroadcast; | |
| 660 Stream<T> asBroadcastStream({ | |
| 661 void onListen(StreamSubscription<T> subscription), void onCancel(StreamSubscript
ion<T> subscription)} | |
| 662 ) => _stream.asBroadcastStream(onListen: onListen, onCancel: onCancel); | |
| 663 StreamSubscription<T> listen(void onData(T value), { | |
| 664 Function onError, void onDone(), bool cancelOnError} | |
| 665 ) { | |
| 666 return _stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: c
ancelOnError); | |
| 667 } | |
| 668 } | |
| 669 abstract class StreamConsumer<S> {Future addStream(Stream<S> stream); | |
| 670 Future close(); | |
| 671 } | |
| 672 abstract class StreamSink<S> implements StreamConsumer<S>, EventSink<S> {Future
close(); | |
| 673 Future get done; | |
| 674 } | |
| 675 abstract class StreamTransformer<S, T> {const factory StreamTransformer(StreamS
ubscription<T> transformer(Stream<S> stream, bool cancelOnError)) = _StreamSubsc
riptionTransformer; | |
| 676 factory StreamTransformer.fromHandlers({ | |
| 677 void handleData(S data, EventSink<T> sink), void handleError(Object error, Stack
Trace stackTrace, EventSink<T> sink), void handleDone(EventSink<T> sink)} | |
| 678 ) = _StreamHandlerTransformer; | |
| 679 Stream<T> bind(Stream<S> stream); | |
| 680 } | |
| 681 abstract class StreamIterator<T> {factory StreamIterator(Stream<T> stream) => n
ew _StreamIteratorImpl<T>(stream); | |
| 682 Future<bool> moveNext(); | |
| 683 T get current; | |
| 684 Future cancel(); | |
| 685 } | |
| 686 class _ControllerEventSinkWrapper<T> implements EventSink<T> {EventSink _sink; | |
| 687 _ControllerEventSinkWrapper(this._sink); | |
| 688 void add(T data) { | |
| 689 _sink.add(data); | |
| 690 } | |
| 691 void addError(error, [StackTrace stackTrace]) { | |
| 692 _sink.addError(error, stackTrace); | |
| 693 } | |
| 694 void close() { | |
| 695 _sink.close(); | |
| 696 } | |
| 697 } | |
| 698 typedef EventSink<dynamic> __CastType20<T>(EventSink<T> __u21); | |
| 699 typedef void __CastType22(StreamSubscription<dynamic> __u23); | |
| 700 typedef void __CastType24<T>(StreamSubscription<T> __u25); | |
| 701 typedef dynamic __CastType26(dynamic __u27, StackTrace __u28); | |
| 702 typedef void __CastType38(); | |
| 703 typedef void __CastType39(EventSink<dynamic> __u40); | |
| OLD | NEW |