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

Unified Diff: lib/src/template/utils.dart

Issue 11092092: Support compiling templates in the browser. Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/template/file_system_vm.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/template/utils.dart
diff --git a/lib/src/template/utils.dart b/lib/src/template/utils.dart
index 808ec6514c283fbe5c6b4209b395a2cdd808269d..8f68d0642fc7e47edfda1d824d6ab113d30dbffc 100644
--- a/lib/src/template/utils.dart
+++ b/lib/src/template/utils.dart
@@ -26,7 +26,7 @@ String toCamelCase(String hyphenedName) {
* whatever [callback] returns. The log message will be printed if either
* [:options.showInfo:] or [printTime] are true.
*/
-time(String logMessage, callback(), [bool printTime = false]) {
+time(String logMessage, callback(), {bool printTime: false}) {
final watch = new Stopwatch();
watch.start();
var result = callback();
@@ -38,6 +38,25 @@ time(String logMessage, callback(), [bool printTime = false]) {
return result;
}
+/**
+ * Invokes [callback], logs how long it takes from the moment [callback] is
+ * executed until the future it returns is completed. Returns the future
+ * returned by [callback]. The log message will be printed if either
+ * [:options.showInfo:] or [printTime] are true.
+ */
+Future asyncTime(String logMessage, Future callback(),
+ {bool printTime: false}) {
+ final watch = new Stopwatch();
+ watch.start();
+ return callback()..then((_) {
+ watch.stop();
+ final duration = watch.elapsedInMs();
+ if (options.showInfo || printTime) {
+ print('$logMessage in $GREEN_COLOR$duration ms$NO_COLOR');
+ }
+ });
+}
+
// Color constants used for generating messages.
final String GREEN_COLOR = '\u001b[32m';
final String RED_COLOR = '\u001b[31m';
« no previous file with comments | « lib/src/template/file_system_vm.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698