Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: tests/lib/async/future_test.dart

Issue 11824032: Make a Future returned by the action of Future.whenCompelete delay. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library future_test; 5 library future_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 testImmediate() { 10 testImmediate() {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 completer.complete(42); 334 completer.complete(42);
335 new Timer(0, () { 335 new Timer(0, () {
336 Future later = future.whenComplete(countDown); 336 Future later = future.whenComplete(countDown);
337 later.then((v) { 337 later.then((v) {
338 Expect.equals(42, v); 338 Expect.equals(42, v);
339 countDown(); 339 countDown();
340 }); 340 });
341 }); 341 });
342 } 342 }
343 343
344 testFutureWhenValueFutureValue() {
345 var port = new ReceivePort();
346 int counter = 3;
347 countDown(int expect) {
348 Expect.equals(expect, counter);
349 if (--counter == 0) port.close();
350 }
351 var completer = new Completer();
352 completer.future.whenComplete(() {
353 countDown(3);
354 var completer2 = new Completer();
355 new Timer(10, (_) {
356 countDown(2);
357 completer2.complete(37);
358 });
359 return completer2.future;
360 }).then((v) {
361 Expect.equals(42, v);
362 countDown(1);
363 });
364
365 completer.complete(42);
366 }
367
368 testFutureWhenValueFutureError() {
369 var port = new ReceivePort();
370 int counter = 3;
371 countDown(int expect) {
372 Expect.equals(expect, counter);
373 if (--counter == 0) port.close();
374 }
375 var completer = new Completer();
376 completer.future.whenComplete(() {
377 countDown(3);
378 var completer2 = new Completer();
379 new Timer(10, (_) {
380 countDown(2);
381 completer2.completeError("Fail");
382 });
383 return completer2.future;
384 }).then((v) {
385 Expect.fail("should fail async");
386 }, onError: (AsyncError e) {
387 Expect.equals("Fail", e.error);
388 countDown(1);
389 });
390
391 completer.complete(42);
392 }
393
394 testFutureWhenErrorFutureValue() {
395 var port = new ReceivePort();
396 int counter = 3;
397 countDown(int expect) {
398 Expect.equals(expect, counter);
399 if (--counter == 0) port.close();
400 }
401 var completer = new Completer();
402 completer.future.whenComplete(() {
403 countDown(3);
404 var completer2 = new Completer();
405 new Timer(10, (_) {
406 countDown(2);
407 completer2.complete(37);
408 });
409 return completer2.future;
410 }).then((v) {
411 Expect.fail("should fail async");
412 }, onError: (AsyncError e) {
413 Expect.equals("Error", e.error);
414 countDown(1);
415 });
416
417 completer.completeError("Error");
418 }
419
420 testFutureWhenErrorFutureError() {
421 var port = new ReceivePort();
422 int counter = 3;
423 countDown(int expect) {
424 Expect.equals(expect, counter);
425 if (--counter == 0) port.close();
426 }
427 var completer = new Completer();
428 completer.future.whenComplete(() {
429 countDown(3);
430 var completer2 = new Completer();
431 new Timer(10, (_) {
432 countDown(2);
433 completer2.completeError("Fail");
434 });
435 return completer2.future;
436 }).then((v) {
437 Expect.fail("should fail async");
438 }, onError: (AsyncError e) {
439 Expect.equals("Fail", e.error);
440 countDown(1);
441 });
442
443 completer.completeError("Error");
444 }
445
446
447
344 main() { 448 main() {
345 testImmediate(); 449 testImmediate();
346 testNeverComplete(); 450 testNeverComplete();
347 451
348 testComplete(); 452 testComplete();
349 testCompleteWithSuccessHandlerBeforeComplete(); 453 testCompleteWithSuccessHandlerBeforeComplete();
350 testCompleteWithSuccessHandlerAfterComplete(); 454 testCompleteWithSuccessHandlerAfterComplete();
351 testCompleteManySuccessHandlers(); 455 testCompleteManySuccessHandlers();
352 456
353 testException(); 457 testException();
354 testExceptionHandler(); 458 testExceptionHandler();
355 testExceptionHandlerReturnsTrue(); 459 testExceptionHandlerReturnsTrue();
356 testExceptionHandlerReturnsTrue2(); 460 testExceptionHandlerReturnsTrue2();
357 testExceptionHandlerReturnsFalse(); 461 testExceptionHandlerReturnsFalse();
358 462
359 testFutureAsStreamCompleteAfter(); 463 testFutureAsStreamCompleteAfter();
360 testFutureAsStreamCompleteBefore(); 464 testFutureAsStreamCompleteBefore();
361 testFutureAsStreamCompleteImmediate(); 465 testFutureAsStreamCompleteImmediate();
362 testFutureAsStreamCompleteErrorAfter(); 466 testFutureAsStreamCompleteErrorAfter();
363 testFutureAsStreamWrapper(); 467 testFutureAsStreamWrapper();
364 468
365 testFutureWhenCompleteValue(); 469 testFutureWhenCompleteValue();
366 testFutureWhenCompleteError(); 470 testFutureWhenCompleteError();
367 testFutureWhenCompleteValueNewError(); 471 testFutureWhenCompleteValueNewError();
368 testFutureWhenCompleteErrorNewError(); 472 testFutureWhenCompleteErrorNewError();
473
474 testFutureWhenValueFutureValue();
475 testFutureWhenErrorFutureValue();
476 testFutureWhenValueFutureError();
477 testFutureWhenErrorFutureError();
369 } 478 }
370 479
OLDNEW
« sdk/lib/async/future_impl.dart ('K') | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698