[vm] Remove dart:cli waitFor

Closes https://github.com/dart-lang/sdk/issues/52121

Tested: CI
CoreLibraryReviewExempt: Approved breaking change to VM specific code
Change-Id: Icc89017c5a7676c2ae07488692ad8b8b9e131a7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354880
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Vyacheslav Egorov 2024-02-29 11:18:51 +00:00 committed by Commit Queue
parent 0766f7b83e
commit 9e11d79657
31 changed files with 12 additions and 806 deletions

View file

@ -19,6 +19,10 @@
### Libraries
#### `dart:cli`
- **Breaking change** [#52121][]: `waitFor` is removed in 3.4.
#### `dart:io`
- **Breaking change** [#53863][]: `Stdout` has a new field `lineTerminator`,

View file

@ -12,7 +12,6 @@ import("../vm/heap/heap_sources.gni")
import("../vm/vm_sources.gni")
import("builtin_impl_sources.gni")
import("builtin_sources.gni")
import("cli_impl_sources.gni")
import("cli_sources.gni")
import("io_impl_sources.gni")
import("io_sources.gni")
@ -357,7 +356,7 @@ template("build_gen_snapshot_dart_io") {
defines = [ "DART_IO_SECURE_SOCKET_DISABLED" ]
sources = io_impl_sources + cli_impl_sources
sources = io_impl_sources
sources += [
"io_natives.cc",
"io_natives.h",
@ -476,7 +475,7 @@ template("dart_io") {
}
}
sources = io_impl_sources + cli_impl_sources
sources = io_impl_sources
sources += [
"builtin_natives.cc",
"io_natives.cc",

View file

@ -1,27 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "bin/builtin.h"
#include "bin/dartutils.h"
#include "include/dart_api.h"
namespace dart {
namespace bin {
void FUNCTION_NAME(CLI_WaitForEvent)(Dart_NativeArguments args) {
int64_t timeout_millis;
Dart_Handle result = Dart_GetNativeIntegerArgument(args, 0, &timeout_millis);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
result = Dart_WaitForEvent(timeout_millis);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
Dart_SetReturnValue(args, result);
}
} // namespace bin
} // namespace dart

View file

@ -1,6 +0,0 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file contains some C++ sources for the dart:cli library.
cli_impl_sources = [ "cli.cc" ]

View file

@ -553,11 +553,7 @@ Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) {
}
Dart_Handle DartUtils::PrepareCLILibrary(Dart_Handle cli_lib) {
Dart_Handle wait_for_event_handle =
Dart_Invoke(cli_lib, NewString("_getWaitForEvent"), 0, nullptr);
RETURN_IF_ERROR(wait_for_event_handle);
return Dart_SetField(cli_lib, NewString("_waitForEventClosure"),
wait_for_event_handle);
return Dart_Null();
}
Dart_Handle DartUtils::SetupPackageConfig(const char* packages_config) {

View file

@ -20,7 +20,6 @@ namespace bin {
// Some classes, like File and Directory, list their implementations in
// builtin_natives.cc instead.
#define IO_NATIVE_LIST(V) \
V(CLI_WaitForEvent, 1) \
V(Crypto_GetRandomBytes, 1) \
V(Directory_Create, 2) \
V(Directory_CreateTemp, 2) \

View file

@ -868,7 +868,7 @@ typedef struct Dart_CodeObserver {
* implement registration of kernel blobs for the subsequent Isolate.spawnUri
* If no callback is provided, the registration of kernel blobs will throw
* an error.
*
*
* \param kernel_buffer A buffer which contains a kernel program. Callback
* should copy the contents of `kernel_buffer` as
* it may be freed immediately after registration.
@ -888,7 +888,7 @@ typedef const char* (*Dart_RegisterKernelBlobCallback)(
* unregister kernel blobs.
* If no callback is provided, the unregistration of kernel blobs will throw
* an error.
*
*
* \param kernel_blob_uri URI of the kernel blob to unregister.
*/
typedef void (*Dart_UnregisterKernelBlobCallback)(const char* kernel_blob_uri);
@ -1679,17 +1679,6 @@ DART_EXPORT Dart_Handle Dart_GetStickyError(void);
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_HandleMessage(void);
/**
* Drains the microtask queue, then blocks the calling thread until the current
* isolate receives a message, then handles all messages.
*
* \param timeout_millis When non-zero, the call returns after the indicated
number of milliseconds even if no message was received.
* \return A valid handle if no error occurs, otherwise an error handle.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_WaitForEvent(int64_t timeout_millis);
/**
* Handles any pending messages for the vm service for the current
* isolate.

View file

@ -350,7 +350,6 @@ main() {
"Dart_TypeToNullableType",
"Dart_TypeVoid",
"Dart_VersionString",
"Dart_WaitForEvent",
"Dart_WriteHeapSnapshot",
"Dart_WriteProfileToTimeline",
];

View file

@ -2109,68 +2109,6 @@ DART_EXPORT Dart_Handle Dart_HandleMessage() {
return Api::Success();
}
DART_EXPORT Dart_Handle Dart_WaitForEvent(int64_t timeout_millis) {
if (!FLAG_enable_deprecated_wait_for) {
return Dart_NewUnhandledExceptionError(Dart_NewStringFromCString(
"Synchronous waiting using dart:cli waitFor "
"and C API Dart_WaitForEvent is deprecated and disabled by default. "
"This feature will be fully removed in Dart 3.4 release. "
"You can currently still enable it by passing "
"--enable_deprecated_wait_for "
"to the Dart VM. "
"See https://dartbug.com/52121."));
}
Thread* T = Thread::Current();
Isolate* I = T->isolate();
CHECK_API_SCOPE(T);
CHECK_CALLBACK_STATE(T);
API_TIMELINE_BEGIN_END(T);
TransitionNativeToVM transition(T);
if (I->message_notify_callback() != nullptr) {
return Api::NewError("waitForEventSync is not supported by this embedder");
}
Object& result =
Object::Handle(Z, DartLibraryCalls::EnsureScheduleImmediate());
if (result.IsError()) {
return Api::NewHandle(T, result.ptr());
}
// Drain the microtask queue. Propagate any errors to the entry frame.
result = DartLibraryCalls::DrainMicrotaskQueue();
if (result.IsError()) {
// Persist the error across unwiding scopes before propagating.
const Error* error;
{
NoSafepointScope no_safepoint;
ErrorPtr raw_error = Error::Cast(result).ptr();
T->UnwindScopes(T->top_exit_frame_info());
error = &Error::Handle(T->zone(), raw_error);
}
Exceptions::PropagateToEntry(*error);
UNREACHABLE();
return Api::NewError("Unreachable");
}
// Block to wait for messages and then handle them. Propagate any errors to
// the entry frame.
if (I->message_handler()->PauseAndHandleAllMessages(timeout_millis) !=
MessageHandler::kOK) {
// Persist the error across unwiding scopes before propagating.
const Error* error;
{
NoSafepointScope no_safepoint;
ErrorPtr raw_error = T->StealStickyError();
T->UnwindScopes(T->top_exit_frame_info());
error = &Error::Handle(T->zone(), raw_error);
}
Exceptions::PropagateToEntry(*error);
UNREACHABLE();
return Api::NewError("Unreachable");
}
return Api::Success();
}
DART_EXPORT bool Dart_HandleServiceMessages() {
#if defined(PRODUCT)
return true;

View file

@ -1,9 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:_internal" show patch;
@patch
@pragma("vm:external-name", "CLI_WaitForEvent")
external void _waitForEvent(int timeoutMillis);

View file

@ -7,7 +7,7 @@
/// ## Deprecation notice
///
/// The functionality of this library is incomplete and may be removed in a
/// later version. See [waitFor] for details.
/// later version.
///
/// {@category VM}
@Deprecated(
@ -16,5 +16,3 @@ library dart.cli;
import 'dart:async';
import 'dart:math';
part 'wait_for.dart';

View file

@ -2,9 +2,4 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
cli_sdk_sources = [
"cli.dart",
# The above file needs to be first if additional parts are added to the lib.
"wait_for.dart",
]
cli_sdk_sources = [ "cli.dart" ]

View file

@ -1,164 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of dart.cli;
/**
* Synchronously blocks the calling isolate to wait for asynchronous events to
* complete.
*
* If the [timeout] parameter is supplied, [waitForEvent] will return after
* the specified timeout even if no events have occurred.
*
* This call does the following:
* - suspends the current execution stack,
* - runs the microtask queue until it is empty,
* - waits until the message queue is not empty,
* - handles messages on the message queue, plus their associated microtasks,
* until the message queue is empty,
* - resumes the original stack.
*
* This function breaks the usual promise offered by Dart semantics that
* message handlers and microtasks run to completion before the next message
* handler or microtask begins to run. Of particular note is that use of this
* function in a finally block will allow microtasks and message handlers to
* run before all finally blocks for an exception have completed, possibly
* breaking invariants in your program.
*
* This function will synchronously throw the first unhandled exception it
* encounters in running the microtasks and message handlers as though the
* throwing microtask or message handler was the only Dart invocation on the
* stack. That is, unhandled exceptions in a microtask or message handler will
* skip over stacks suspended in a call to [waitForEvent].
*
* Calls to this function may be nested. Earlier invocations will not
* be able to complete until subsequent ones do. Messages that arrive after
* a subsequent invocation are "consumed" by that invocation, and do not
* unblock an earlier invocation. Please be aware that nesting calls to
* [waitForEvent] can lead to deadlock when subsequent calls block to wait for
* a condition that is only satisfied after an earlier call returns.
*
* Please note that this call is only available in the standalone command-line
* Dart VM. Further, because it suspends the current execution stack until the
* message queue is empty, even when running in the standalone command-line VM
* there exists a risk that the current execution stack will be starved.
*/
external void _waitForEvent(int timeoutMillis);
@pragma("vm:entry-point")
void Function(int) _getWaitForEvent() => _waitForEvent;
// This should be set from C++ code by the embedder to wire up waitFor() to the
// native implementation. In the standalone VM this is set to _waitForEvent()
// above. If it is null, calling waitFor() will throw an UnsupportedError.
@pragma("vm:entry-point")
void Function(int)? _waitForEventClosure;
class _WaitForUtils {
static void waitForEvent({Duration? timeout}) {
final closure = _waitForEventClosure;
if (closure == null) {
throw new UnsupportedError("waitFor is not supported by this embedder");
}
closure(timeout == null ? 0 : max(1, timeout.inMilliseconds));
}
}
/**
* Suspends the stack, runs microtasks, and handles incoming events until
* [future] completes.
*
* ## Deprecation notice
*
* The `waitFor` feature is deprecated, disabled by default and slated for
* removal in Dart 3.4 release.
*
* See https://dartbug.com/52121
*
* During transitionary period you can still force enable this feature
* by passing --enable-deprecated-wait-for to Dart VM.
*
* ## Call semantics
*
* This call does the following:
* - While [future] is not completed:
* - suspends the current execution stack,
* - runs the microtask queue until it is empty,
* - waits until the message queue is not empty,
* - handles messages on the message queue, plus their associated microtasks,
* until the message queue is empty,
* - resumes the original stack.
*
* This function breaks the usual promise offered by Dart semantics that
* message handlers and microtasks run to completion before the next message
* handler or microtask begins to run. Of particular note is that use of this
* function in a finally block will allow microtasks and message handlers to
* run before all finally blocks for an exception have completed, possibly
* breaking invariants in your program.
*
* Use of this function should be considered a last resort when it is not
* possible to convert a Dart program entirely to an asynchronous style using
* `async` and `await`.
*
* If the [Future] completes normally, its result is returned. If the [Future]
* completes with an error, the error and stack trace are wrapped in an
* [AsyncError] and thrown. If a microtask or message handler run during this
* call results in an unhandled exception, that exception will be propagated
* as though the microtask or message handler was the only Dart invocation on
* the stack. That is, unhandled exceptions in a microtask or message handler
* will skip over stacks suspended in a call to [waitFor].
*
* If the optional `timeout` parameter is passed, [waitFor] throws a
* [TimeoutException] if the [Future] is not completed within the specified
* period.
*
* Calls to [waitFor] may be nested. Earlier invocations will not complete
* until subsequent ones do, but the completion of a subsequent invocation will
* cause the previous invocation to wake up and check its [Future] for
* completion.
*
* Please be aware that nesting calls to [waitFor] can lead to deadlock if
* subsequent calls block waiting for a condition that is only satisfied when
* an earlier call returns.
*/
@Deprecated("This functionality is deprecated and will be removed in Dart 3.4")
T waitFor<T>(Future<T> future, {Duration? timeout}) {
late T result;
bool futureCompleted = false;
Object? error;
StackTrace? stacktrace;
future.then((T r) {
futureCompleted = true;
result = r;
}, onError: (e, st) {
error = e;
stacktrace = st;
});
late Stopwatch s;
if (timeout != null) {
s = new Stopwatch()..start();
}
Timer.run(() {}); // Ensure there is at least one message.
while (!futureCompleted && (error == null)) {
Duration? remaining;
if (timeout != null) {
if (s.elapsed >= timeout) {
throw new TimeoutException("waitFor() timed out", timeout);
}
remaining = timeout - s.elapsed;
}
_WaitForUtils.waitForEvent(timeout: remaining);
}
if (timeout != null) {
s.stop();
}
Timer.run(() {}); // Ensure that previous calls to waitFor are woken up.
if (error != null) {
throw new AsyncError(error!, stacktrace);
}
return result;
}

View file

@ -124,10 +124,7 @@
],
"libraries": {
"cli": {
"uri": "cli/cli.dart",
"patches": [
"_internal/vm/bin/cli_patch.dart"
]
"uri": "cli/cli.dart"
}
}
},

View file

@ -116,8 +116,6 @@ vm:
libraries:
cli:
uri: "cli/cli.dart"
patches:
- "_internal/vm/bin/cli_patch.dart"
wasm:
include:

View file

@ -1,22 +0,0 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
main() {
asyncStart();
Completer<Null> c = new Completer<Null>();
Timer.run(() {
c.complete(null);
asyncEnd();
});
Null result = waitFor<Null>(c.future);
Expect.isNull(result);
}

View file

@ -1,23 +0,0 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This test verifies that attempting to use `waitFor` without enabling it
// causes an exception.
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
main() {
asyncStart();
Expect.throws<String>(() {
waitFor(Future.delayed(Duration(milliseconds: 10)).whenComplete(asyncEnd));
}, (v) {
return v.contains('deprecated and disabled') &&
v.contains('dartbug.com/52121') &&
v.contains('enable_deprecated_wait_for');
});
}

View file

@ -1,21 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
main() {
asyncStart();
Completer<bool> c = new Completer<bool>();
Timer.run(() {
c.completeError("Error", StackTrace.current);
asyncEnd();
});
Expect.throws(() => waitFor<bool>(c.future), (e) => e is AsyncError);
}

View file

@ -1,24 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:mirrors';
import 'dart:cli';
late void Function({Duration timeout}) waitForEvent;
void initWaitForEvent() {
LibraryMirror lib = currentMirrorSystem().findLibrary(#dart.cli);
for (Symbol s in lib.declarations.keys) {
if (s.toString().contains("_WaitForUtils")) {
DeclarationMirror d = lib.declarations[s]!;
ClassMirror utils = (d as ClassMirror);
for (Symbol m in utils.staticMembers.keys) {
if (m.toString().contains("waitForEvent")) {
waitForEvent = utils.getField(m).reflectee;
}
}
}
}
}

View file

@ -1,45 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:isolate';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that waitForEvent() returns on an Isolate message.
messageSender(SendPort s) {
new Timer(const Duration(seconds: 1), () {
s.send(true);
});
}
main() {
initWaitForEvent();
asyncStart();
bool flag1 = false;
bool flag2 = false;
ReceivePort r = new ReceivePort();
Isolate.spawn(messageSender, r.sendPort).then((Isolate i) {
r.listen((message) {
flag1 = true;
});
Expect.isFalse(flag1);
waitForEvent();
Expect.isTrue(flag1);
r.close();
flag2 = true;
});
Expect.isFalse(flag1);
Expect.isFalse(flag2);
waitForEvent();
Expect.isTrue(flag1);
Expect.isTrue(flag2);
asyncEnd();
}

View file

@ -1,28 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that microtasks are run before waitForEvent() blocks.
main() {
initWaitForEvent();
asyncStart();
bool flag = false;
scheduleMicrotask(() {
flag = true;
asyncEnd();
});
Expect.isFalse(flag);
waitForEvent(timeout: const Duration(milliseconds: 10));
Expect.isTrue(flag);
}

View file

@ -1,38 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that waitForEvent() drains microtasks before blocking even when
// called from a microtask.
main() {
initWaitForEvent();
asyncStart();
bool flag1 = false;
bool flag2 = false;
scheduleMicrotask(() {
scheduleMicrotask(() {
flag1 = true;
asyncEnd();
});
Expect.isFalse(flag1);
waitForEvent(timeout: const Duration(milliseconds: 10));
Expect.isTrue(flag1);
flag2 = true;
});
Expect.isFalse(flag1);
Expect.isFalse(flag2);
waitForEvent(timeout: const Duration(milliseconds: 10));
Expect.isTrue(flag1);
Expect.isTrue(flag2);
}

View file

@ -1,31 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that the microtasks for a message handler are run before
// waitForEvent() returns.
main() {
initWaitForEvent();
asyncStart();
bool flag = false;
Timer.run(() {
scheduleMicrotask(() {
flag = true;
asyncEnd();
});
});
Expect.isFalse(flag);
waitForEvent();
Expect.isTrue(flag);
}

View file

@ -1,34 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that all messages are processed before waitForEvent() returns.
main() {
initWaitForEvent();
asyncStart();
bool flag = false;
Timer.run(() {
Timer.run(() {
Timer.run(() {
Timer.run(() {
flag = true;
asyncEnd();
});
});
});
});
Expect.isFalse(flag);
waitForEvent();
Expect.isTrue(flag);
}

View file

@ -1,73 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that waitForEvent() works when called from a message handler.
main() {
initWaitForEvent();
asyncStart();
bool flag1 = false;
bool flag2 = false;
bool flag3 = false;
bool flag4 = false;
Timer.run(() {
Timer.run(() {
Timer.run(() {
Timer.run(() {
flag1 = true;
asyncEnd();
});
Expect.isFalse(flag1);
Expect.isFalse(flag2);
Expect.isFalse(flag3);
Expect.isFalse(flag4);
waitForEvent();
Expect.isTrue(flag1);
Expect.isFalse(flag2);
Expect.isFalse(flag3);
Expect.isFalse(flag4);
flag2 = true;
});
Expect.isFalse(flag1);
Expect.isFalse(flag2);
Expect.isFalse(flag3);
Expect.isFalse(flag4);
waitForEvent();
Expect.isTrue(flag1);
Expect.isTrue(flag2);
Expect.isFalse(flag3);
Expect.isFalse(flag4);
flag3 = true;
});
Expect.isFalse(flag1);
Expect.isFalse(flag2);
Expect.isFalse(flag3);
Expect.isFalse(flag4);
waitForEvent();
Expect.isTrue(flag1);
Expect.isTrue(flag2);
Expect.isTrue(flag3);
Expect.isFalse(flag4);
flag4 = true;
});
Expect.isFalse(flag1);
Expect.isFalse(flag2);
Expect.isFalse(flag3);
Expect.isFalse(flag4);
waitForEvent();
Expect.isTrue(flag1);
Expect.isTrue(flag2);
Expect.isTrue(flag3);
Expect.isTrue(flag4);
}

View file

@ -1,28 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that waitForEvent() works in a simple case.
main() {
initWaitForEvent();
asyncStart();
bool flag = false;
Timer.run(() {
flag = true;
asyncEnd();
});
Expect.isFalse(flag);
waitForEvent();
Expect.isTrue(flag);
}

View file

@ -1,33 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that waitForEvent() doesn't cause an error to escape a Zone that
// has an error handler.
main() {
initWaitForEvent();
asyncStart();
bool flag = false;
runZonedGuarded(() {
Timer.run(() {
asyncEnd();
throw "Exception";
});
}, (e, s) {
flag = true;
});
Expect.isFalse(flag);
waitForEvent();
Expect.isTrue(flag);
}

View file

@ -1,31 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'wait_for_event_helper.dart';
// Tests that waitForEvent() works even when the message handler is run in
// a different Zone.
main() {
initWaitForEvent();
asyncStart();
bool flag = false;
runZoned(() {
Timer.run(() {
flag = true;
asyncEnd();
});
});
Expect.isFalse(flag);
waitForEvent();
Expect.isTrue(flag);
}

View file

@ -1,26 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
main() {
asyncStart();
Completer<bool> c = new Completer<bool>();
runZonedGuarded(() {
Timer.run(() {
asyncEnd();
throw "Error";
});
}, (e, s) {
Expect.isTrue(e is String);
c.complete(true);
});
Expect.isTrue(waitFor<bool>(c.future));
}

View file

@ -1,23 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:mirrors';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
main() {
asyncStart();
Completer<bool> c = new Completer<bool>();
Timer.run(() {
c.complete(true);
asyncEnd();
});
bool result = waitFor<bool>(c.future);
Expect.isTrue(result);
}

View file

@ -1,20 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable-deprecated-wait-for
import 'dart:async';
import 'dart:cli';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
main() {
asyncStart();
Completer<bool> c = new Completer<bool>();
Expect.throws(() {
waitFor<bool>(c.future, timeout: const Duration(seconds: 1));
}, (e) => e is TimeoutException);
asyncEnd();
}