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

Side by Side Diff: pkg/shelf/lib/src/util.dart

Issue 256753004: pkg/shelf: change helper method on Request and Response (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nevermind Created 6 years, 7 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 | « pkg/shelf/lib/src/shelf_unmodifiable_map.dart ('k') | pkg/shelf/test/message_change_test.dart » ('j') | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 shelf.util; 5 library shelf.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:stack_trace/stack_trace.dart'; 9 import 'package:stack_trace/stack_trace.dart';
10 10
11 /// Like [Future.sync], but wraps the Future in [Chain.track] as well. 11 /// Like [Future.sync], but wraps the Future in [Chain.track] as well.
12 Future syncFuture(callback()) => Chain.track(new Future.sync(callback)); 12 Future syncFuture(callback()) => Chain.track(new Future.sync(callback));
13 13
14 /// Run [callback] and capture any errors that would otherwise be top-leveled. 14 /// Run [callback] and capture any errors that would otherwise be top-leveled.
15 /// 15 ///
16 /// If [this] is called in a non-root error zone, it will just run [callback] 16 /// If [this] is called in a non-root error zone, it will just run [callback]
17 /// and return the result. Otherwise, it will capture any errors using 17 /// and return the result. Otherwise, it will capture any errors using
18 /// [runZoned] and pass them to [onError]. 18 /// [runZoned] and pass them to [onError].
19 catchTopLevelErrors(callback(), void onError(error, StackTrace stackTrace)) { 19 catchTopLevelErrors(callback(), void onError(error, StackTrace stackTrace)) {
20 if (Zone.current.inSameErrorZone(Zone.ROOT)) { 20 if (Zone.current.inSameErrorZone(Zone.ROOT)) {
21 return runZoned(callback, onError: onError); 21 return runZoned(callback, onError: onError);
22 } else { 22 } else {
23 return callback(); 23 return callback();
24 } 24 }
25 } 25 }
26
27 /// Returns a [Map] with the values from [original] and the values from
28 /// [updates].
29 ///
30 /// For keys that are the same between [original] and [updates], the value in
31 /// [updates] is used.
32 ///
33 /// If [updates] is `null` or empty, [original] is returned unchanged.
34 Map updateMap(Map original, Map updates) {
35 if (updates == null || updates.isEmpty) return original;
36
37 return new Map.from(original)
38 ..addAll(updates);
39 }
OLDNEW
« no previous file with comments | « pkg/shelf/lib/src/shelf_unmodifiable_map.dart ('k') | pkg/shelf/test/message_change_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698