Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
db35611e
Unverified
Commit
db35611e
authored
Oct 06, 2022
by
Jia Hao
Committed by
GitHub
Oct 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schedule tasks which are futures to completion (#112269)
parent
98c04987
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
binding.dart
packages/flutter/lib/src/scheduler/binding.dart
+7
-3
scheduler_test.dart
packages/flutter/test/scheduler/scheduler_test.dart
+25
-0
No files found.
packages/flutter/lib/src/scheduler/binding.dart
View file @
db35611e
...
...
@@ -50,7 +50,7 @@ typedef FrameCallback = void Function(Duration timeStamp);
///
/// The type argument `T` is the task's return value. Consider `void` if the
/// task does not return a value.
typedef
TaskCallback
<
T
>
=
T
Function
();
typedef
TaskCallback
<
T
>
=
FutureOr
<
T
>
Function
();
/// Signature for the [SchedulerBinding.schedulingStrategy] callback. Called
/// whenever the system needs to decide whether a task at a given
...
...
@@ -409,8 +409,12 @@ mixin SchedulerBinding on BindingBase {
}
final
PriorityQueue
<
_TaskEntry
<
dynamic
>>
_taskQueue
=
HeapPriorityQueue
<
_TaskEntry
<
dynamic
>>(
_taskSorter
);
/// Schedules the given `task` with the given `priority` and returns a
/// [Future] that completes to the `task`'s eventual return value.
/// Schedules the given `task` with the given `priority`.
///
/// If `task` returns a future, the future returned by [scheduleTask] will
/// complete after the former future has been scheduled to completion.
/// Otherwise, the returned future for [scheduleTask] will complete with the
/// same value returned by `task` after it has been scheduled.
///
/// The `debugLabel` and `flow` are used to report the task to the [Timeline],
/// for use when profiling.
...
...
packages/flutter/test/scheduler/scheduler_test.dart
View file @
db35611e
...
...
@@ -250,6 +250,31 @@ void main() {
warmUpDrawFrame
();
expect
(
scheduler
.
hasScheduledFrame
,
isTrue
);
});
test
(
'Can schedule futures to completion'
,
()
async
{
bool
isCompleted
=
false
;
// `Future` is disallowed in this file due to the import of
// scheduler_tester.dart so annotations cannot be specified.
// ignore: always_specify_types
final
result
=
scheduler
.
scheduleTask
(
()
async
{
// Yield, so if awaiting `result` did not wait for completion of this
// task, the assertion on `isCompleted` will fail.
await
null
;
await
null
;
isCompleted
=
true
;
return
1
;
},
Priority
.
idle
,
);
scheduler
.
handleEventLoopCallback
();
await
result
;
expect
(
isCompleted
,
true
);
});
}
class
DummyTimer
implements
Timer
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment