4d7d29039a
Change-Id: Ibbf93373b594e2fc3e5909747d586c062376e6c0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400760 Auto-Submit: Nate Biggs <natebiggs@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
32 lines
764 B
Dart
32 lines
764 B
Dart
// Copyright (c) 2024, 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 'package:expect/async_helper.dart';
|
|
|
|
class Foo {
|
|
bool disposed = false;
|
|
|
|
void dispose() {
|
|
if (disposed) throw 'Used disposed foo';
|
|
disposed = true;
|
|
}
|
|
}
|
|
|
|
Future<void> main() async {
|
|
asyncStart();
|
|
List<Function> callbacks = [];
|
|
for (final x in [1, 2]) {
|
|
final Foo foo = Foo();
|
|
callbacks.add(() {
|
|
// This closure should capture the foo from this loop iteration and only
|
|
// dispose each one once.
|
|
foo.dispose();
|
|
});
|
|
}
|
|
for (final callback in callbacks) {
|
|
callback();
|
|
}
|
|
asyncEnd();
|
|
}
|