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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 25002002: Add a default value for bindCallback's runGuarded. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of dart.async; 5 part of dart.async;
6 6
7 typedef dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 9
10 typedef dynamic HandleUncaughtErrorHandler( 10 typedef dynamic HandleUncaughtErrorHandler(
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 dynamic runGuarded(f()); 244 dynamic runGuarded(f());
245 245
246 /** 246 /**
247 * Executes the given callback [f] in this zone. 247 * Executes the given callback [f] in this zone.
248 * 248 *
249 * Same as [runUnary] but catches uncaught errors and gives them to 249 * Same as [runUnary] but catches uncaught errors and gives them to
250 * [handleUncaughtError]. 250 * [handleUncaughtError].
251 */ 251 */
252 dynamic runUnaryGuarded(f(arg), var arg); 252 dynamic runUnaryGuarded(f(arg), var arg);
253 253
254 ZoneCallback registerCallback(f()); 254 /**
255 ZoneUnaryCallback registerUnaryCallback(f(arg)); 255 * Registers the given callback in this zone.
256 *
257 * It is good practice to register asynchronous or delayed callbacks before
258 * invoking [run]. This gives the zone a chance to wrap the callback and
259 * to store information with the callback. For example, a zone may decide
260 * to store the stack trace (at the time of the registration) with the
261 * callback.
262 *
263 * Returns a potentially new callback that should be used in place of the
264 * given [callback].
265 */
266 ZoneCallback registerCallback(callback());
267
268 /**
269 * Registers the given callback in this zone.
270 *
271 * Similar to [registerCallback] but with a unary callback.
272 */
273 ZoneUnaryCallback registerUnaryCallback(callback(arg));
256 274
257 /** 275 /**
258 * Equivalent to: 276 * Equivalent to:
259 * 277 *
260 * ZoneCallback registered = registerCallback(f); 278 * ZoneCallback registered = registerCallback(f);
279 * if (runGuarded) return () => this.runGuarded(registered);
261 * return () => this.run(registered); 280 * return () => this.run(registered);
281 *
262 */ 282 */
263 ZoneCallback bindCallback(f(), { bool runGuarded }); 283 ZoneCallback bindCallback(f(), { bool runGuarded: true });
264 /** 284 /**
265 * Equivalent to: 285 * Equivalent to:
266 * 286 *
267 * ZoneCallback registered = registerCallback1(f); 287 * ZoneCallback registered = registerCallback1(f);
268 * return (arg) => this.run1(registered, arg); 288 * if (runGuarded) return (arg) => this.runUnaryGuarded(registered, arg);
289 * return (arg) => thin.runUnary(registered, arg);
269 */ 290 */
270 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded }); 291 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true });
271 292
272 /** 293 /**
273 * Runs [f] asynchronously. 294 * Runs [f] asynchronously.
274 */ 295 */
275 void scheduleMicrotask(void f()); 296 void scheduleMicrotask(void f());
276 297
277 /** 298 /**
278 * Creates a Timer where the callback is executed in this zone. 299 * Creates a Timer where the callback is executed in this zone.
279 */ 300 */
280 Timer createTimer(Duration duration, void callback()); 301 Timer createTimer(Duration duration, void callback());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 441 }
421 442
422 dynamic runUnaryGuarded(f(arg), arg) { 443 dynamic runUnaryGuarded(f(arg), arg) {
423 try { 444 try {
424 return runUnary(f, arg); 445 return runUnary(f, arg);
425 } catch (e, s) { 446 } catch (e, s) {
426 return handleUncaughtError(_asyncError(e, s)); 447 return handleUncaughtError(_asyncError(e, s));
427 } 448 }
428 } 449 }
429 450
430 ZoneCallback bindCallback(f(), { bool runGuarded }) { 451 ZoneCallback bindCallback(f(), { bool runGuarded: true }) {
431 ZoneCallback registered = registerCallback(f); 452 ZoneCallback registered = registerCallback(f);
432 if (runGuarded) { 453 if (runGuarded) {
433 return () => this.runGuarded(registered); 454 return () => this.runGuarded(registered);
434 } else { 455 } else {
435 return () => this.run(registered); 456 return () => this.run(registered);
436 } 457 }
437 } 458 }
438 459
439 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded }) { 460 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }) {
440 ZoneUnaryCallback registered = registerUnaryCallback(f); 461 ZoneUnaryCallback registered = registerUnaryCallback(f);
441 if (runGuarded) { 462 if (runGuarded) {
442 return (arg) => this.runUnaryGuarded(registered, arg); 463 return (arg) => this.runUnaryGuarded(registered, arg);
443 } else { 464 } else {
444 return (arg) => this.runUnary(registered, arg); 465 return (arg) => this.runUnary(registered, arg);
445 } 466 }
446 } 467 }
447 468
448 operator [](Symbol key) { 469 operator [](Symbol key) {
449 var result = _map[key]; 470 var result = _map[key];
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 ZoneSpecification specification = 725 ZoneSpecification specification =
705 new ZoneSpecification(handleUncaughtError: errorHandler, 726 new ZoneSpecification(handleUncaughtError: errorHandler,
706 scheduleMicrotask: asyncHandler); 727 scheduleMicrotask: asyncHandler);
707 Zone zone = Zone.current.fork(specification: specification); 728 Zone zone = Zone.current.fork(specification: specification);
708 if (onError != null) { 729 if (onError != null) {
709 return zone.runGuarded(body); 730 return zone.runGuarded(body);
710 } else { 731 } else {
711 return zone.run(body); 732 return zone.run(body);
712 } 733 }
713 } 734 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698