Skip to content

Commit 0f98533

Browse files
authored
[web] Delete unused futurize util (flutter#177861)
1 parent afbfaf9 commit 0f98533

File tree

3 files changed

+5
-118
lines changed

3 files changed

+5
-118
lines changed

engine/src/flutter/lib/web_ui/lib/painting.dart

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -596,21 +596,14 @@ enum PixelFormat { rgba8888, bgra8888, rgbaFloat32 }
596596
typedef ImageDecoderCallback = void Function(Image result);
597597

598598
abstract class FrameInfo {
599-
FrameInfo._();
600-
Duration get duration => Duration(milliseconds: _durationMillis);
601-
int get _durationMillis => 0;
599+
Duration get duration;
602600
Image get image;
603601
}
604602

605-
class Codec {
606-
Codec._();
607-
int get frameCount => 0;
608-
int get repetitionCount => 0;
609-
Future<FrameInfo> getNextFrame() {
610-
return engine.futurize<FrameInfo>(_getNextFrame);
611-
}
612-
613-
String? _getNextFrame(engine.Callback<FrameInfo> callback) => null;
603+
abstract class Codec {
604+
int get frameCount;
605+
int get repetitionCount;
606+
Future<FrameInfo> getNextFrame();
614607
void dispose() {}
615608
}
616609

engine/src/flutter/lib/web_ui/lib/src/engine/util.dart

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:async';
65
import 'dart:collection';
76
import 'dart:convert';
87
import 'dart:math' as math;
@@ -15,61 +14,6 @@ import 'browser_detection.dart' show isIOS15, isMacOrIOS;
1514
import 'dom.dart';
1615
import 'vector_math.dart';
1716

18-
/// Generic callback signature, used by [futurize].
19-
typedef Callback<T> = void Function(T result);
20-
21-
/// Signature for a method that receives a [Callback].
22-
///
23-
/// Return value should be null on success, and a string error message on
24-
/// failure.
25-
typedef Callbacker<T> = String? Function(Callback<T> callback);
26-
27-
/// Converts a method that receives a value-returning callback to a method that
28-
/// returns a Future.
29-
///
30-
/// Return a [String] to cause an [Exception] to be synchronously thrown with
31-
/// that string as a message.
32-
///
33-
/// If the callback is called with null, the future completes with an error.
34-
///
35-
/// Example usage:
36-
///
37-
/// ```dart
38-
/// typedef IntCallback = void Function(int result);
39-
///
40-
/// String _doSomethingAndCallback(IntCallback callback) {
41-
/// Timer(const Duration(seconds: 1), () { callback(1); });
42-
/// }
43-
///
44-
/// Future<int> doSomething() {
45-
/// return futurize(_doSomethingAndCallback);
46-
/// }
47-
/// ```
48-
// Keep this in sync with _futurize in lib/ui/fixtures/ui_test.dart.
49-
Future<T> futurize<T>(Callbacker<T> callbacker) {
50-
final Completer<T> completer = Completer<T>.sync();
51-
// If the callback synchronously throws an error, then synchronously
52-
// rethrow that error instead of adding it to the completer. This
53-
// prevents the Zone from receiving an uncaught exception.
54-
bool isSync = true;
55-
final String? error = callbacker((T? t) {
56-
if (t == null) {
57-
if (isSync) {
58-
throw Exception('operation failed');
59-
} else {
60-
completer.completeError(Exception('operation failed'));
61-
}
62-
} else {
63-
completer.complete(t);
64-
}
65-
});
66-
isSync = false;
67-
if (error != null) {
68-
throw Exception(error);
69-
}
70-
return completer.future;
71-
}
72-
7317
/// Converts [matrix] to CSS transform value.
7418
String matrix4ToCssTransform(Matrix4 matrix) {
7519
return float64ListToCssTransform(matrix.storage);

engine/src/flutter/lib/web_ui/test/engine/util_test.dart

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:async';
65
import 'dart:typed_data';
76

87
import 'package:test/bootstrap/browser.dart';
@@ -106,55 +105,6 @@ void testMain() {
106105
expect(element.style.color, '');
107106
});
108107

109-
test('futurize turns a Callbacker into a Future', () async {
110-
final Future<String> stringFuture = futurize((Callback<String> callback) {
111-
scheduleMicrotask(() {
112-
callback('hello');
113-
});
114-
return null;
115-
});
116-
expect(await stringFuture, 'hello');
117-
});
118-
119-
test('futurize converts error string to exception', () async {
120-
try {
121-
await futurize((Callback<String> callback) {
122-
return 'this is an error';
123-
});
124-
fail('Expected it to throw');
125-
} on Exception catch (exception) {
126-
expect('$exception', contains('this is an error'));
127-
}
128-
});
129-
130-
test('futurize converts async null into an async operation failure', () async {
131-
final Future<String?> stringFuture = futurize((Callback<String?> callback) {
132-
scheduleMicrotask(() {
133-
callback(null);
134-
});
135-
return null;
136-
});
137-
138-
try {
139-
await stringFuture;
140-
fail('Expected it to throw');
141-
} on Exception catch (exception) {
142-
expect('$exception', contains('operation failed'));
143-
}
144-
});
145-
146-
test('futurize converts sync null into a sync operation failure', () async {
147-
try {
148-
await futurize((Callback<String?> callback) {
149-
callback(null);
150-
return null;
151-
});
152-
fail('Expected it to throw');
153-
} on Exception catch (exception) {
154-
expect('$exception', contains('operation failed'));
155-
}
156-
});
157-
158108
test('unordered list equality', () {
159109
expect(unorderedListEqual<int>(null, null), isTrue);
160110
expect(unorderedListEqual<int>(<int>[], null), isTrue);

0 commit comments

Comments
 (0)