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

Side by Side Diff: pkg/scheduled_test/lib/src/schedule.dart

Issue 93143002: Make pkg/stack_trace use stack chains. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: more fixes Created 7 years 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 schedule; 5 library schedule;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 Future schedule(fn(), [String description]) { 419 Future schedule(fn(), [String description]) {
420 if (isRunning) { 420 if (isRunning) {
421 var task = _schedule.currentTask; 421 var task = _schedule.currentTask;
422 var wrappedFn = () => _schedule.wrapFuture( 422 var wrappedFn = () => _schedule.wrapFuture(
423 new Future.value().then((_) => fn())); 423 new Future.value().then((_) => fn()));
424 if (task == null) return wrappedFn(); 424 if (task == null) return wrappedFn();
425 return task.runChild(wrappedFn, description); 425 return task.runChild(wrappedFn, description);
426 } 426 }
427 427
428 var task = new Task(() { 428 var task = new Task(() {
429 return new Future.sync(fn).catchError((e, stackTrace) { 429 return syncFuture(fn).catchError((e, stackTrace) {
430 throw new ScheduleError.from(_schedule, e, stackTrace: stackTrace); 430 throw new ScheduleError.from(_schedule, e, stackTrace: stackTrace);
431 }); 431 });
432 }, description, this); 432 }, description, this);
433 _contents.add(task); 433 _contents.add(task);
434 return task.result; 434 return task.result;
435 } 435 }
436 436
437 /// Runs all the tasks in this queue in order. 437 /// Runs all the tasks in this queue in order.
438 Future _run() { 438 Future _run() {
439 _schedule._currentQueue = this; 439 _schedule._currentQueue = this;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 /// function has been called. It's used to ensure that out-of-band callbacks 488 /// function has been called. It's used to ensure that out-of-band callbacks
489 /// are properly handled by the scheduled test. 489 /// are properly handled by the scheduled test.
490 Function _wrapAsync(fn(arg), String description) { 490 Function _wrapAsync(fn(arg), String description) {
491 assert(_schedule.state == ScheduleState.SET_UP || isRunning); 491 assert(_schedule.state == ScheduleState.SET_UP || isRunning);
492 492
493 // It's possible that the queue timed out before [fn] finished. 493 // It's possible that the queue timed out before [fn] finished.
494 bool _timedOut() => 494 bool _timedOut() =>
495 _schedule.currentQueue != this || pendingCallbacks.isEmpty; 495 _schedule.currentQueue != this || pendingCallbacks.isEmpty;
496 496
497 _totalCallbacks++; 497 _totalCallbacks++;
498 var trace = new Trace.current(); 498 var chain = new Chain.current();
499 var pendingCallback = new PendingCallback._(() { 499 var pendingCallback = new PendingCallback._(() {
500 var fullDescription = description; 500 var fullDescription = description;
501 if (fullDescription == null) { 501 if (fullDescription == null) {
502 fullDescription = "Out-of-band operation #${_totalCallbacks}"; 502 fullDescription = "Out-of-band operation #${_totalCallbacks}";
503 } 503 }
504 504
505 var stackString = prefixLines(terseTraceString(trace)); 505 var stackString = prefixLines(terseTraceString(chain));
Bob Nystrom 2013/12/03 22:24:47 Should this be "terseChainString" now?
nweiz 2013/12/03 22:34:32 It still takes a StackTrace; it will just play nic
506 fullDescription += "\n\nStack trace:\n$stackString"; 506 fullDescription += "\n\nStack chain:\n$stackString";
507 return fullDescription; 507 return fullDescription;
508 }); 508 });
509 _pendingCallbacks.add(pendingCallback); 509 _pendingCallbacks.add(pendingCallback);
510 510
511 return (arg) { 511 return (arg) {
512 try { 512 try {
513 return fn(arg); 513 return fn(arg);
514 } catch (e, stackTrace) { 514 } catch (e, stackTrace) {
515 var error = new ScheduleError.from( 515 var error = new ScheduleError.from(
516 _schedule, e, stackTrace: stackTrace); 516 _schedule, e, stackTrace: stackTrace);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 /// The string description of the callback. 609 /// The string description of the callback.
610 String get description { 610 String get description {
611 if (_description == null) _description = _thunk(); 611 if (_description == null) _description = _thunk();
612 return _description; 612 return _description;
613 } 613 }
614 614
615 String toString() => description; 615 String toString() => description;
616 616
617 PendingCallback._(this._thunk); 617 PendingCallback._(this._thunk);
618 } 618 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698