OLD | NEW |
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 utils; | 5 library utils; |
6 | 6 |
| 7 import 'dart:async'; |
7 import 'dart:math'; | 8 import 'dart:math'; |
8 | 9 |
9 class Utils { | 10 class Utils { |
10 | 11 |
11 static String formatPercentNormalized(double x) { | 12 static String formatPercentNormalized(double x) { |
12 var percent = 100.0 * x; | 13 var percent = 100.0 * x; |
13 return '${percent.toStringAsFixed(2)}%'; | 14 return '${percent.toStringAsFixed(2)}%'; |
14 } | 15 } |
15 | 16 |
16 static String formatPercent(num a, num total) { | 17 static String formatPercent(num a, num total) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 134 } |
134 return '${seconds}s'; | 135 return '${seconds}s'; |
135 } | 136 } |
136 | 137 |
137 static String formatSeconds(double x) { | 138 static String formatSeconds(double x) { |
138 return x.toStringAsFixed(2); | 139 return x.toStringAsFixed(2); |
139 } | 140 } |
140 | 141 |
141 static bool runningInJavaScript() => identical(1.0, 1); | 142 static bool runningInJavaScript() => identical(1.0, 1); |
142 } | 143 } |
| 144 |
| 145 /// A [Task] that can be scheduled on the Dart event queue. |
| 146 class Task { |
| 147 Timer _timer; |
| 148 final Function callback; |
| 149 |
| 150 Task(this.callback); |
| 151 |
| 152 /// Queue [this] to run on the next Dart event queue pump. Does nothing |
| 153 /// if [this] is already queued. |
| 154 queue() { |
| 155 if (_timer != null) { |
| 156 // Already scheduled. |
| 157 return; |
| 158 } |
| 159 _timer = new Timer(Duration.ZERO, () { |
| 160 _timer = null; |
| 161 callback(); |
| 162 }); |
| 163 } |
| 164 } |
OLD | NEW |