dartfmt
diff --git a/example/http_server.dart b/example/http_server.dart
index 92ca9c7..415b687 100644
--- a/example/http_server.dart
+++ b/example/http_server.dart
@@ -95,14 +95,14 @@
await ServerSocket.bind(InternetAddress.ANY_IP_V6, port, shared: true);
port = socket.port;
- var isolates = await Future.wait(
- new Iterable.generate(5, (_) => IsolateRunner.spawn()),
- cleanUp: (isolate) {
+ var isolates = await Future
+ .wait(new Iterable.generate(5, (_) => IsolateRunner.spawn()),
+ cleanUp: (isolate) {
isolate.close();
});
- List<RemoteStop> stoppers = await Future.wait(isolates
- .map((IsolateRunner isolate) {
+ List<RemoteStop> stoppers =
+ await Future.wait(isolates.map((IsolateRunner isolate) {
return runHttpServer(isolate, socket.port, listener);
}), cleanUp: (server) {
server.stop();
diff --git a/example/runner_pool.dart b/example/runner_pool.dart
index 7773a12..cb08da2 100644
--- a/example/runner_pool.dart
+++ b/example/runner_pool.dart
@@ -30,21 +30,23 @@
// Compute fibonacci 1..limit
Future<List<int>> parfib(int limit, int parallelity) {
- return LoadBalancer.create(parallelity, IsolateRunner.spawn).then(
- (LoadBalancer pool) {
- var fibs = new List<Future<int>>(limit + 1);
- // Schedule all calls with exact load value and the heaviest task
- // assigned first.
- schedule(a, b, i) {
- if (i < limit) {
- schedule(a + b, a, i + 1);
- }
- fibs[i] = pool.run(fib, i, load: a);
+ return LoadBalancer
+ .create(parallelity, IsolateRunner.spawn)
+ .then((LoadBalancer pool) {
+ var fibs = new List<Future<int>>(limit + 1);
+ // Schedule all calls with exact load value and the heaviest task
+ // assigned first.
+ schedule(a, b, i) {
+ if (i < limit) {
+ schedule(a + b, a, i + 1);
}
- schedule(0, 1, 0);
- // And wait for them all to complete.
- return Future.wait(fibs).whenComplete(pool.close);
- });
+ fibs[i] = pool.run(fib, i, load: a);
+ }
+
+ schedule(0, 1, 0);
+ // And wait for them all to complete.
+ return Future.wait(fibs).whenComplete(pool.close);
+ });
}
int computeFib(int n) {
diff --git a/lib/isolate_runner.dart b/lib/isolate_runner.dart
index fbfe4d6..da518f3 100644
--- a/lib/isolate_runner.dart
+++ b/lib/isolate_runner.dart
@@ -54,8 +54,8 @@
/// The created isolate is set to have errors not be fatal.
static Future<IsolateRunner> spawn() async {
var channel = new SingleResponseChannel();
- var isolate = await Isolate.spawn(IsolateRunnerRemote._create,
- channel.port);
+ var isolate =
+ await Isolate.spawn(IsolateRunnerRemote._create, channel.port);
// The runner can be used to run multiple independent functions.
// An accidentally uncaught error shouldn't ruin it for everybody else.
isolate.setErrorsFatal(false);
@@ -126,9 +126,8 @@
/// (like pause and resume) have been handled.
/// Paused isolates do respond to ping requests.
Future<bool> ping({Duration timeout: const Duration(seconds: 1)}) {
- var channel = new SingleResponseChannel(callback: _kTrue,
- timeout: timeout,
- timeoutValue: false);
+ var channel = new SingleResponseChannel(
+ callback: _kTrue, timeout: timeout, timeoutValue: false);
isolate.ping(channel.port);
return channel.result;
}
@@ -213,6 +212,7 @@
controller.addError(error, error.stackTrace);
}
}
+
controller = new StreamController.broadcast(
sync: true,
onListen: () {
@@ -289,8 +289,8 @@
Function function = command[1];
var argument = command[2];
SendPort responsePort = command[3];
- sendFutureResult(new Future.sync(() => function(argument)),
- responsePort);
+ sendFutureResult(
+ new Future.sync(() => function(argument)), responsePort);
return;
}
}
diff --git a/lib/load_balancer.dart b/lib/load_balancer.dart
index 4ff066d..cd7c193 100644
--- a/lib/load_balancer.dart
+++ b/lib/load_balancer.dart
@@ -48,8 +48,9 @@
/// var isolatePool = LoadBalancer.create(10, IsolateRunner.spawn);
static Future<LoadBalancer> create(int size, Future<Runner> createRunner()) {
return Future.wait(new Iterable.generate(size, (_) => createRunner()),
- cleanUp: (Runner runner) { runner.close(); })
- .then((runners) => new LoadBalancer(runners));
+ cleanUp: (Runner runner) {
+ runner.close();
+ }).then((runners) => new LoadBalancer(runners));
}
static List<_LoadBalancerEntry> _createEntries(Iterable<Runner> runners) {
@@ -68,9 +69,8 @@
/// If [timeout] and [onTimeout] are provided, they are forwarded to
/// the runner running the function, which will handle a timeout
/// as normal.
- Future run(function(argument), argument, {Duration timeout,
- onTimeout(),
- int load: 100}) {
+ Future run(function(argument), argument,
+ {Duration timeout, onTimeout(), int load: 100}) {
RangeError.checkNotNegative(load, "load");
_LoadBalancerEntry entry = _first;
_increaseLoad(entry, load);
@@ -92,14 +92,12 @@
/// the runners running the function, which will handle any timeouts
/// as normal.
List<Future> runMultiple(int count, function(argument), argument,
- {Duration timeout,
- onTimeout(),
- int load: 100}) {
+ {Duration timeout, onTimeout(), int load: 100}) {
RangeError.checkValueInInterval(count, 1, _length, "count");
RangeError.checkNotNegative(load, "load");
if (count == 1) {
- return list1(run(function, argument, load: load,
- timeout: timeout, onTimeout: onTimeout));
+ return list1(run(function, argument,
+ load: load, timeout: timeout, onTimeout: onTimeout));
}
List result = new List<Future>(count);
if (count == _length) {
@@ -166,7 +164,7 @@
/// swap it with the highest priority child.
void _bubbleDown(_LoadBalancerEntry element, int index) {
while (true) {
- int childIndex = index * 2 + 1; // Left child index.
+ int childIndex = index * 2 + 1; // Left child index.
if (childIndex >= _length) break;
_LoadBalancerEntry child = _queue[childIndex];
int rightChildIndex = childIndex + 1;
@@ -268,9 +266,10 @@
bool get inQueue => queueIndex >= 0;
Future run(LoadBalancer balancer, int load, function(argument), argument,
- Duration timeout, onTimeout()) {
- return runner.run(function, argument,
- timeout: timeout, onTimeout: onTimeout).whenComplete(() {
+ Duration timeout, onTimeout()) {
+ return runner
+ .run(function, argument, timeout: timeout, onTimeout: onTimeout)
+ .whenComplete(() {
balancer._decreaseLoad(this, load);
});
}
diff --git a/lib/ports.dart b/lib/ports.dart
index 4a185fe..7f95e56 100644
--- a/lib/ports.dart
+++ b/lib/ports.dart
@@ -43,8 +43,7 @@
/// ..first.timeout(duration, () => timeoutValue).then(callback))
/// .sendPort
SendPort singleCallbackPort(void callback(response),
- {Duration timeout,
- var timeoutValue}) {
+ {Duration timeout, var timeoutValue}) {
RawReceivePort responsePort = new RawReceivePort();
Zone zone = Zone.current;
callback = zone.registerUnaryCallback(callback);
@@ -89,9 +88,7 @@
///
/// Returns the `SendPort` expecting the single message.
SendPort singleCompletePort(Completer completer,
- {callback(message),
- Duration timeout,
- onTimeout()}) {
+ {callback(message), Duration timeout, onTimeout()}) {
if (callback == null && timeout == null) {
return singleCallbackPort(completer.complete);
}
@@ -121,7 +118,7 @@
completer.complete(new Future.sync(onTimeout));
} else {
completer.completeError(
- new TimeoutException("Future not completed", timeout));
+ new TimeoutException("Future not completed", timeout));
}
});
}
@@ -149,8 +146,7 @@
/// use the [timeout] parameter, and not [Future.timeout] on the result.
/// The `Future` method won't be able to close the underlying [ReceivePort].
Future singleResponseFuture(void action(SendPort responsePort),
- {Duration timeout,
- var timeoutValue}) {
+ {Duration timeout, var timeoutValue}) {
Completer completer = new Completer.sync();
RawReceivePort responsePort = new RawReceivePort();
Timer timer;
@@ -181,21 +177,19 @@
return completer.future;
}
-
/// Send the result of a future, either value or error, as a message.
///
/// The result of [future] is sent on [resultPort] in a form expected by
/// either [receiveFutureResult], [completeFutureResult], or
/// by the port of [singleResultFuture].
void sendFutureResult(Future future, SendPort resultPort) {
- future.then(
- (v) { resultPort.send(list1(v));
+ future.then((v) {
+ resultPort.send(list1(v));
}, onError: (e, s) {
resultPort.send(list2("$e", "$s"));
});
}
-
/// Creates a [Future], and a [SendPort] that can be used to complete that
/// future.
///
@@ -215,13 +209,10 @@
/// If `onTimeout` is omitted, it defaults to throwing
/// a [TimeoutException].
Future singleResultFuture(void action(SendPort responsePort),
- {Duration timeout,
- onTimeout()}) {
+ {Duration timeout, onTimeout()}) {
Completer completer = new Completer.sync();
SendPort port = singleCompletePort(completer,
- callback: receiveFutureResult,
- timeout: timeout,
- onTimeout: onTimeout);
+ callback: receiveFutureResult, timeout: timeout, onTimeout: onTimeout);
try {
action(port);
} catch (e, s) {
@@ -244,7 +235,6 @@
}
}
-
/// Converts a received message created by [sendFutureResult] to a future
/// result.
///
@@ -284,11 +274,12 @@
/// the future is completed with the result of running `onTimeout()`.
/// If `onTimeout` is not provided either,
/// the future is completed with `timeoutValue`, which defaults to `null`.
- SingleResponseChannel({callback(value),
- Duration timeout,
- bool throwOnTimeout: false,
- onTimeout(),
- var timeoutValue})
+ SingleResponseChannel(
+ {callback(value),
+ Duration timeout,
+ bool throwOnTimeout: false,
+ onTimeout(),
+ var timeoutValue})
: _receivePort = new RawReceivePort(),
_completer = new Completer.sync(),
_callback = callback,
diff --git a/lib/registry.dart b/lib/registry.dart
index 2054ae2..37014ee 100644
--- a/lib/registry.dart
+++ b/lib/registry.dart
@@ -67,7 +67,7 @@
/// this registry should wait before assuming that an operation
/// has failed.
Registry.fromPort(SendPort commandPort,
- {Duration timeout: const Duration(seconds: 5)})
+ {Duration timeout: const Duration(seconds: 5)})
: _commandPort = commandPort,
_timeout = timeout;
@@ -112,16 +112,19 @@
});
}
Completer completer = new Completer<Capability>();
- SendPort port = singleCompletePort(completer, callback: (List response) {
- assert(cache.isAdding(element));
- int id = response[0];
- Capability removeCapability = response[1];
- cache.register(id, element);
- return removeCapability;
- }, timeout: _timeout, onTimeout: () {
- cache.stopAdding(element);
- throw new TimeoutException("Future not completed", _timeout);
- });
+ SendPort port = singleCompletePort(completer,
+ callback: (List response) {
+ assert(cache.isAdding(element));
+ int id = response[0];
+ Capability removeCapability = response[1];
+ cache.register(id, element);
+ return removeCapability;
+ },
+ timeout: _timeout,
+ onTimeout: () {
+ cache.stopAdding(element);
+ throw new TimeoutException("Future not completed", _timeout);
+ });
if (tags != null) tags = tags.toList(growable: false);
cache.setAdding(element);
_commandPort.send(list4(_ADD, element, tags, port));
@@ -367,7 +370,7 @@
assert(tags.isNotEmpty);
for (int id in ids) {
_RegistryEntry entry = _entries[id];
- if (entry == null) continue; // Entry was removed.
+ if (entry == null) continue; // Entry was removed.
entry.tags.addAll(tags);
for (var tag in tags) {
Set ids = _tag2id.putIfAbsent(tag, _createSet);
@@ -382,7 +385,7 @@
assert(tags.isNotEmpty);
for (int id in ids) {
_RegistryEntry entry = _entries[id];
- if (entry == null) continue; // Object was removed.
+ if (entry == null) continue; // Object was removed.
entry.tags.removeAll(tags);
}
for (var tag in tags) {
@@ -436,7 +439,7 @@
return;
}
var matchingIds = _findTaggedIds(tags);
- if (max == null) max = matchingIds.length; // All results.
+ if (max == null) max = matchingIds.length; // All results.
for (var id in matchingIds) {
result.add(id);
result.add(_entries[id].element);
diff --git a/lib/runner.dart b/lib/runner.dart
index 46cee67..018dcd8 100644
--- a/lib/runner.dart
+++ b/lib/runner.dart
@@ -36,7 +36,7 @@
///
/// The default implementation runs the function in the current isolate.
Future run(function(argument), Object argument,
- {Duration timeout, onTimeout()}) {
+ {Duration timeout, onTimeout()}) {
Future result = new Future.sync(() => function(argument));
if (timeout != null) {
result = result.timeout(timeout, onTimeout: onTimeout);
diff --git a/lib/src/errors.dart b/lib/src/errors.dart
index 058af90..a5813da 100644
--- a/lib/src/errors.dart
+++ b/lib/src/errors.dart
@@ -41,7 +41,7 @@
/// The order of values is not preserved (if that is needed, use
/// [wait]).
static Future<List> waitUnordered(Iterable<Future> futures,
- {cleanUp(successResult)}) {
+ {cleanUp(successResult)}) {
Completer completer;
int count = 0;
int errors = 0;
@@ -59,6 +59,7 @@
var errorList = results.sublist(results.length - errors);
completer.completeError(new MultiError(errorList));
}
+
var handleValue = (v) {
// If this fails because [results] is null, there is a future
// which breaks the Future API by completing immediately when
@@ -116,6 +117,7 @@
}
completer.completeError(new MultiError(results));
}
+
for (Future future in futures) {
int i = count;
count++;
diff --git a/lib/src/lists.dart b/lib/src/lists.dart
index 2047ab3..24c0010 100644
--- a/lib/src/lists.dart
+++ b/lib/src/lists.dart
@@ -9,23 +9,27 @@
List list1(v1) => new List(1)..[0] = v1;
/// Create a two-element fixed-length list.
-List list2(v1, v2) => new List(2)..[0] = v1
- ..[1] = v2;
+List list2(v1, v2) => new List(2)
+ ..[0] = v1
+ ..[1] = v2;
/// Create a three-element fixed-length list.
-List list3(v1, v2, v3) => new List(3)..[0] = v1
- ..[1] = v2
- ..[2] = v3;
+List list3(v1, v2, v3) => new List(3)
+ ..[0] = v1
+ ..[1] = v2
+ ..[2] = v3;
/// Create a four-element fixed-length list.
-List list4(v1, v2, v3, v4) => new List(4)..[0] = v1
- ..[1] = v2
- ..[2] = v3
- ..[3] = v4;
+List list4(v1, v2, v3, v4) => new List(4)
+ ..[0] = v1
+ ..[1] = v2
+ ..[2] = v3
+ ..[3] = v4;
/// Create a five-element fixed-length list.
-List list5(v1, v2, v3, v4, v5) => new List(5)..[0] = v1
- ..[1] = v2
- ..[2] = v3
- ..[3] = v4
- ..[4] = v5;
+List list5(v1, v2, v3, v4, v5) => new List(5)
+ ..[0] = v1
+ ..[1] = v2
+ ..[2] = v3
+ ..[3] = v4
+ ..[4] = v5;
diff --git a/lib/src/raw_receive_port_multiplexer.dart b/lib/src/raw_receive_port_multiplexer.dart
index 0e45f4b..00843ad 100644
--- a/lib/src/raw_receive_port_multiplexer.dart
+++ b/lib/src/raw_receive_port_multiplexer.dart
@@ -88,7 +88,7 @@
_MultiplexRawReceivePort receivePort = _map[id];
// If the receive port is closed, messages are dropped, just as for
// the normal ReceivePort.
- if (receivePort == null) return; // Port closed.
+ if (receivePort == null) return; // Port closed.
receivePort._invokeHandler(message);
}
diff --git a/test/isolaterunner_test.dart b/test/isolaterunner_test.dart
index 7a3a48d..ab22e34 100644
--- a/test/isolaterunner_test.dart
+++ b/test/isolaterunner_test.dart
@@ -36,25 +36,24 @@
Future testSeparateIsolates() {
// Check that each isolate has its own _global variable.
- return Future.wait(new Iterable.generate(2, (_) => IsolateRunner.spawn()))
- .then((runners) {
- Future runAll(action(IsolateRunner runner, int index)) {
- var indices = new Iterable.generate(runners.length);
- return Future.wait(indices.map((i) => action(runners[i], i)));
- }
+ return Future
+ .wait(new Iterable.generate(2, (_) => IsolateRunner.spawn()))
+ .then((runners) {
+ Future runAll(action(IsolateRunner runner, int index)) {
+ var indices = new Iterable.generate(runners.length);
+ return Future.wait(indices.map((i) => action(runners[i], i)));
+ }
- return runAll((runner, i) => runner.run(setGlobal, i + 1))
- .then((values) {
- expect(values, [1, 2]);
- expect(_global, null);
- return runAll((runner, _) => runner.run(getGlobal, null));
- })
- .then((values) {
- expect(values, [1, 2]);
- expect(_global, null);
- return runAll((runner, _) => runner.close());
- });
+ return runAll((runner, i) => runner.run(setGlobal, i + 1)).then((values) {
+ expect(values, [1, 2]);
+ expect(_global, null);
+ return runAll((runner, _) => runner.run(getGlobal, null));
+ }).then((values) {
+ expect(values, [1, 2]);
+ expect(_global, null);
+ return runAll((runner, _) => runner.close());
});
+ });
}
void testIsolateFunctions() {
diff --git a/test/ports_test.dart b/test/ports_test.dart
index 322b540..77f3604 100644
--- a/test/ports_test.dart
+++ b/test/ports_test.dart
@@ -68,8 +68,7 @@
test("TimeoutFirst", () {
Completer completer = new Completer.sync();
SendPort p = singleCallbackPort(completer.complete,
- timeout: MS * 100,
- timeoutValue: 37);
+ timeout: MS * 100, timeoutValue: 37);
new Timer(MS * 500, () => p.send(42));
return completer.future.then((v) {
expect(v, 37);
@@ -77,7 +76,6 @@
});
}
-
void testSingleCompletePort() {
test("Value", () {
Completer completer = new Completer.sync();
@@ -104,8 +102,7 @@
Completer completer = new Completer.sync();
SendPort p = singleCompletePort(completer, callback: (v) {
expect(42, v);
- return new Future.delayed(MS * 500,
- () => 88);
+ return new Future.delayed(MS * 500, () => 88);
});
p.send(42);
return completer.future.then((v) {
@@ -154,9 +151,9 @@
test("FirstValueCallback", () {
Completer completer = new Completer.sync();
SendPort p = singleCompletePort(completer, callback: (v) {
- expect(v, 42);
- return 87;
- });
+ expect(v, 42);
+ return 87;
+ });
p.send(42);
p.send(37);
return completer.future.then((v) {
@@ -204,8 +201,7 @@
test("TimeoutCallbackFuture", () {
Completer completer = new Completer.sync();
singleCompletePort(completer,
- timeout: MS * 100,
- onTimeout: () => new Future.value(87));
+ timeout: MS * 100, onTimeout: () => new Future.value(87));
return completer.future.then((v) {
expect(v, 87);
});
@@ -214,8 +210,7 @@
test("TimeoutCallbackThrowsFuture", () {
Completer completer = new Completer.sync();
singleCompletePort(completer,
- timeout: MS * 100,
- onTimeout: () => new Future.error(92));
+ timeout: MS * 100, onTimeout: () => new Future.error(92));
return completer.future.then((v) {
fail("unreachable");
}, onError: (e, s) {
@@ -225,8 +220,7 @@
test("TimeoutCallbackSLow", () {
Completer completer = new Completer.sync();
- singleCompletePort(
- completer,
+ singleCompletePort(completer,
timeout: MS * 100,
onTimeout: () => new Future.delayed(MS * 500, () => 87));
return completer.future.then((v) {
@@ -236,8 +230,7 @@
test("TimeoutCallbackThrowsSlow", () {
Completer completer = new Completer.sync();
- singleCompletePort(
- completer,
+ singleCompletePort(completer,
timeout: MS * 100,
onTimeout: () => new Future.delayed(MS * 500, () => throw 87));
return completer.future.then((v) {
@@ -382,7 +375,7 @@
}
void testSingleResponseChannel() {
- test("Value", () {
+ test("Value", () {
var channel = new SingleResponseChannel();
channel.port.send(42);
return channel.result.then((v) {
@@ -410,15 +403,16 @@
test("ErrorCallback", () {
var channel = new SingleResponseChannel(callback: (v) => throw 42);
channel.port.send(37);
- return channel.result.then((v) { fail("unreachable"); },
- onError: (v, s) {
- expect(v, 42);
- });
+ return channel.result.then((v) {
+ fail("unreachable");
+ }, onError: (v, s) {
+ expect(v, 42);
+ });
});
test("AsyncValueCallback", () {
- var channel = new SingleResponseChannel(
- callback: (v) => new Future.value(v * 2));
+ var channel =
+ new SingleResponseChannel(callback: (v) => new Future.value(v * 2));
channel.port.send(42);
return channel.result.then((v) {
expect(v, 84);
@@ -426,13 +420,14 @@
});
test("AsyncErrorCallback", () {
- var channel = new SingleResponseChannel(callback:
- (v) => new Future.error(42));
+ var channel =
+ new SingleResponseChannel(callback: (v) => new Future.error(42));
channel.port.send(37);
- return channel.result.then((v) { fail("unreachable"); },
- onError: (v, s) {
- expect(v, 42);
- });
+ return channel.result.then((v) {
+ fail("unreachable");
+ }, onError: (v, s) {
+ expect(v, 42);
+ });
});
test("Timeout", () {
@@ -443,75 +438,77 @@
});
test("TimeoutThrow", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- throwOnTimeout: true);
- return channel.result.then((v) { fail("unreachable"); },
- onError: (v, s) {
- expect(v is TimeoutException, isTrue);
- });
+ var channel =
+ new SingleResponseChannel(timeout: MS * 100, throwOnTimeout: true);
+ return channel.result.then((v) {
+ fail("unreachable");
+ }, onError: (v, s) {
+ expect(v is TimeoutException, isTrue);
+ });
});
test("TimeoutThrowOnTimeoutAndValue", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- throwOnTimeout: true,
- onTimeout: () => 42,
- timeoutValue: 42);
- return channel.result.then((v) { fail("unreachable"); },
- onError: (v, s) {
- expect(v is TimeoutException, isTrue);
- });
+ var channel = new SingleResponseChannel(
+ timeout: MS * 100,
+ throwOnTimeout: true,
+ onTimeout: () => 42,
+ timeoutValue: 42);
+ return channel.result.then((v) {
+ fail("unreachable");
+ }, onError: (v, s) {
+ expect(v is TimeoutException, isTrue);
+ });
});
test("TimeoutOnTimeout", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- onTimeout: () => 42);
+ var channel =
+ new SingleResponseChannel(timeout: MS * 100, onTimeout: () => 42);
return channel.result.then((v) {
expect(v, 42);
});
});
test("TimeoutOnTimeoutAndValue", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- onTimeout: () => 42,
- timeoutValue: 37);
+ var channel = new SingleResponseChannel(
+ timeout: MS * 100, onTimeout: () => 42, timeoutValue: 37);
return channel.result.then((v) {
expect(v, 42);
});
});
test("TimeoutValue", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- timeoutValue: 42);
+ var channel =
+ new SingleResponseChannel(timeout: MS * 100, timeoutValue: 42);
return channel.result.then((v) {
expect(v, 42);
});
});
test("TimeoutOnTimeoutError", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- onTimeout: () => throw 42);
- return channel.result.then((v) { fail("unreachable"); },
- onError: (v, s) {
- expect(v, 42);
- });
+ var channel =
+ new SingleResponseChannel(timeout: MS * 100, onTimeout: () => throw 42);
+ return channel.result.then((v) {
+ fail("unreachable");
+ }, onError: (v, s) {
+ expect(v, 42);
+ });
});
test("TimeoutOnTimeoutAsync", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- onTimeout:
- () => new Future.value(42));
+ var channel = new SingleResponseChannel(
+ timeout: MS * 100, onTimeout: () => new Future.value(42));
return channel.result.then((v) {
expect(v, 42);
});
});
test("TimeoutOnTimeoutAsyncError", () {
- var channel = new SingleResponseChannel(timeout: MS * 100,
- onTimeout:
- () => new Future.error(42));
- return channel.result.then((v) { fail("unreachable"); },
- onError: (v, s) {
- expect(v, 42);
- });
+ var channel = new SingleResponseChannel(
+ timeout: MS * 100, onTimeout: () => new Future.error(42));
+ return channel.result.then((v) {
+ fail("unreachable");
+ }, onError: (v, s) {
+ expect(v, 42);
+ });
});
}
diff --git a/test/registry_test.dart b/test/registry_test.dart
index 9c1fbf5..a69aa1f 100644
--- a/test/registry_test.dart
+++ b/test/registry_test.dart
@@ -47,9 +47,8 @@
}).then((all) {
expect(all.length, 10);
expect(all.map((v) => v.id).toList()..sort(),
- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
- })
- .whenComplete(regman.close);
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
+ }).whenComplete(regman.close);
});
test("Odd", () {
@@ -60,13 +59,11 @@
var tag = i.isEven ? Oddity.EVEN : Oddity.ODD;
return registry.add(element, tags: [tag]);
}).then((_) {
- return registry.lookup(tags:[Oddity.ODD]);
+ return registry.lookup(tags: [Oddity.ODD]);
}).then((all) {
expect(all.length, 5);
- expect(all.map((v) => v.id).toList()..sort(),
- [1, 3, 5, 7, 9]);
- })
- .whenComplete(regman.close);
+ expect(all.map((v) => v.id).toList()..sort(), [1, 3, 5, 7, 9]);
+ }).whenComplete(regman.close);
});
test("Max", () {
@@ -80,8 +77,7 @@
return registry.lookup(max: 5);
}).then((all) {
expect(all.length, 5);
- })
- .whenComplete(regman.close);
+ }).whenComplete(regman.close);
});
test("MultiTag", () {
@@ -99,10 +95,8 @@
return registry.lookup(tags: [2, 3]);
}).then((all) {
expect(all.length, 5);
- expect(all.map((v) => v.id).toList()..sort(),
- [0, 6, 12, 18, 24]);
- })
- .whenComplete(regman.close);
+ expect(all.map((v) => v.id).toList()..sort(), [0, 6, 12, 18, 24]);
+ }).whenComplete(regman.close);
});
test("MultiTagMax", () {
@@ -121,8 +115,7 @@
}).then((all) {
expect(all.length, 3);
expect(all.every((v) => (v.id % 6) == 0), isTrue);
- })
- .whenComplete(regman.close);
+ }).whenComplete(regman.close);
});
}
@@ -361,6 +354,7 @@
_regmen[id] = regman;
return regman.registry;
}
+
void closeRegMan(id) {
_regmen.remove(id).close();
}
@@ -515,6 +509,7 @@
}).whenComplete(regman.close);
});
}
+
// Test objects that are sendable between equivalent isolates and
// that has an operator== that works after cloning (for use as tags).
testObject(42);