Unverified Commit 8735ab1e authored by Dan Field's avatar Dan Field Committed by GitHub

Make onImage re-entrant safe (#50316)

parent 7b074468
......@@ -88,11 +88,15 @@ Future<void> precacheImage(
ImageStreamListener listener;
listener = ImageStreamListener(
(ImageInfo image, bool sync) {
completer.complete();
if (!completer.isCompleted) {
completer.complete();
}
stream.removeListener(listener);
},
onError: (dynamic exception, StackTrace stackTrace) {
completer.complete();
if (!completer.isCompleted) {
completer.complete();
}
stream.removeListener(listener);
if (onError != null) {
onError(exception, stackTrace);
......
......@@ -639,13 +639,17 @@ void main() {
)
);
expect(imageStreamCompleter.listeners.length, 2);
imageStreamCompleter.listeners.toList()[1].onImage(null, null);
// Two listeners - one is the listener added by precacheImage, the other by the ImageCache.
final List<ImageStreamListener> listeners = imageStreamCompleter.listeners.toList();
expect(listeners.length, 2);
expect(imageStreamCompleter.listeners.length, 1);
imageStreamCompleter.listeners.toList()[0].onImage(null, null);
// Make sure the first listener can be called re-entrantly
listeners[1].onImage(null, null);
listeners[1].onImage(null, null);
expect(imageStreamCompleter.listeners.length, 0);
// Make sure the second listener can be called re-entrantly.
listeners[0].onImage(null, null);
listeners[0].onImage(null, null);
});
testWidgets('Precache completes with onError on error', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment