Skip to content

Commit c9e9622

Browse files
authored
[camera]do not sleep to avoid hang due to merged thread (flutter#13289)
Previously, before thread merge, this worked, because sleep only blocks the UI thread. Now, after thread merge, the UI thread and platform thread are the same. So sleep would block all the internal setups (such as dart's event channel set up and DispatchQueue.main.async calls on the native side. Fixes flutter#194397 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 8866126 commit c9e9622

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎packages/camera/camera_avfoundation/example/integration_test/camera_test.dart‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void main() {
108108

109109
// Take Video
110110
await controller.startVideoRecording();
111-
sleep(const Duration(milliseconds: 300));
111+
await Future<void>.delayed(const Duration(milliseconds: 300));
112112
final XFile file = await controller.stopVideoRecording();
113113

114114
// Load video metadata
@@ -163,23 +163,23 @@ void main() {
163163

164164
await controller.startVideoRecording();
165165
final int recordingStart = DateTime.now().millisecondsSinceEpoch;
166-
sleep(const Duration(milliseconds: 500));
166+
await Future<void>.delayed(const Duration(milliseconds: 500));
167167

168168
await controller.pauseVideoRecording();
169169
startPause = DateTime.now().millisecondsSinceEpoch;
170-
sleep(const Duration(milliseconds: 500));
170+
await Future<void>.delayed(const Duration(milliseconds: 500));
171171
await controller.resumeVideoRecording();
172172
timePaused += DateTime.now().millisecondsSinceEpoch - startPause;
173173

174-
sleep(const Duration(milliseconds: 500));
174+
await Future<void>.delayed(const Duration(milliseconds: 500));
175175

176176
await controller.pauseVideoRecording();
177177
startPause = DateTime.now().millisecondsSinceEpoch;
178-
sleep(const Duration(milliseconds: 500));
178+
await Future<void>.delayed(const Duration(milliseconds: 500));
179179
await controller.resumeVideoRecording();
180180
timePaused += DateTime.now().millisecondsSinceEpoch - startPause;
181181

182-
sleep(const Duration(milliseconds: 500));
182+
await Future<void>.delayed(const Duration(milliseconds: 500));
183183

184184
final XFile file = await controller.stopVideoRecording();
185185
final int recordingTime = DateTime.now().millisecondsSinceEpoch - recordingStart;
@@ -292,7 +292,7 @@ void main() {
292292
}
293293
},
294294
);
295-
sleep(const Duration(milliseconds: 500));
295+
await Future<void>.delayed(const Duration(milliseconds: 500));
296296
await controller.stopVideoRecording();
297297
await controller.dispose();
298298

@@ -339,7 +339,7 @@ void main() {
339339

340340
// Take Video
341341
await controller.startVideoRecording();
342-
sleep(const Duration(milliseconds: 500));
342+
await Future<void>.delayed(const Duration(milliseconds: 500));
343343
final XFile file = await controller.stopVideoRecording();
344344

345345
// Load video size
@@ -380,7 +380,7 @@ void main() {
380380

381381
// Take Video
382382
await controller.startVideoRecording();
383-
sleep(const Duration(milliseconds: 500));
383+
await Future<void>.delayed(const Duration(milliseconds: 500));
384384
final XFile file = await controller.stopVideoRecording();
385385

386386
// Load video size
@@ -425,7 +425,7 @@ void main() {
425425

426426
// Take Video
427427
await controller.startVideoRecording();
428-
sleep(const Duration(milliseconds: 1000));
428+
await Future<void>.delayed(const Duration(milliseconds: 1000));
429429
final XFile file = await controller.stopVideoRecording();
430430

431431
// Load video metadata

0 commit comments

Comments
 (0)