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
88d50f78
Commit
88d50f78
authored
Apr 04, 2019
by
Nikita
Committed by
Michael Goderbauer
Apr 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement compute for async function (#16265) (#30275)
parent
0c01a557
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
isolates.dart
packages/flutter/lib/src/foundation/isolates.dart
+6
-6
isolates_test.dart
packages/flutter/test/foundation/isolates_test.dart
+11
-0
No files found.
packages/flutter/lib/src/foundation/isolates.dart
View file @
88d50f78
...
@@ -18,7 +18,7 @@ import 'constants.dart';
...
@@ -18,7 +18,7 @@ import 'constants.dart';
/// of classes, not closures or instance methods of objects.
/// of classes, not closures or instance methods of objects.
///
///
/// {@macro flutter.foundation.compute.limitations}
/// {@macro flutter.foundation.compute.limitations}
typedef
ComputeCallback
<
Q
,
R
>
=
R
Function
(
Q
message
);
typedef
ComputeCallback
<
Q
,
R
>
=
FutureOr
<
R
>
Function
(
Q
message
);
/// Spawn an isolate, run `callback` on that isolate, passing it `message`, and
/// Spawn an isolate, run `callback` on that isolate, passing it `message`, and
/// (eventually) return the value returned by `callback`.
/// (eventually) return the value returned by `callback`.
...
@@ -53,9 +53,9 @@ Future<R> compute<Q, R>(ComputeCallback<Q, R> callback, Q message, { String debu
...
@@ -53,9 +53,9 @@ Future<R> compute<Q, R>(ComputeCallback<Q, R> callback, Q message, { String debu
final
ReceivePort
resultPort
=
ReceivePort
();
final
ReceivePort
resultPort
=
ReceivePort
();
final
ReceivePort
errorPort
=
ReceivePort
();
final
ReceivePort
errorPort
=
ReceivePort
();
Timeline
.
finishSync
();
Timeline
.
finishSync
();
final
Isolate
isolate
=
await
Isolate
.
spawn
<
_IsolateConfiguration
<
Q
,
R
>>(
final
Isolate
isolate
=
await
Isolate
.
spawn
<
_IsolateConfiguration
<
Q
,
FutureOr
<
R
>
>>(
_spawn
,
_spawn
,
_IsolateConfiguration
<
Q
,
R
>(
_IsolateConfiguration
<
Q
,
FutureOr
<
R
>
>(
callback
,
callback
,
message
,
message
,
resultPort
.
sendPort
,
resultPort
.
sendPort
,
...
@@ -110,11 +110,11 @@ class _IsolateConfiguration<Q, R> {
...
@@ -110,11 +110,11 @@ class _IsolateConfiguration<Q, R> {
R
apply
()
=>
callback
(
message
);
R
apply
()
=>
callback
(
message
);
}
}
void
_spawn
<
Q
,
R
>(
_IsolateConfiguration
<
Q
,
R
>
configuration
)
{
Future
<
void
>
_spawn
<
Q
,
R
>(
_IsolateConfiguration
<
Q
,
FutureOr
<
R
>>
configuration
)
async
{
R
result
;
R
result
;
Timeline
.
timeSync
(
await
Timeline
.
timeSync
(
'
${configuration.debugLabel}
'
,
'
${configuration.debugLabel}
'
,
()
{
result
=
configuration
.
apply
();
},
()
async
{
result
=
await
configuration
.
apply
();
},
flow:
Flow
.
step
(
configuration
.
flowId
),
flow:
Flow
.
step
(
configuration
.
flowId
),
);
);
Timeline
.
timeSync
(
Timeline
.
timeSync
(
...
...
packages/flutter/test/foundation/isolates_test.dart
View file @
88d50f78
...
@@ -14,9 +14,20 @@ int test2(int value) {
...
@@ -14,9 +14,20 @@ int test2(int value) {
throw
2
;
throw
2
;
}
}
Future
<
int
>
test1Async
(
int
value
)
async
{
return
value
+
1
;
}
Future
<
int
>
test2Async
(
int
value
)
async
{
throw
2
;
}
void
main
(
)
{
void
main
(
)
{
test
(
'compute()'
,
()
async
{
test
(
'compute()'
,
()
async
{
expect
(
await
compute
(
test1
,
0
),
1
);
expect
(
await
compute
(
test1
,
0
),
1
);
expect
(
compute
(
test2
,
0
),
throwsA
(
isInstanceOf
<
Exception
>()));
expect
(
compute
(
test2
,
0
),
throwsA
(
isInstanceOf
<
Exception
>()));
expect
(
await
compute
(
test1Async
,
0
),
1
);
expect
(
compute
(
test2Async
,
0
),
throwsA
(
isInstanceOf
<
Exception
>()));
});
});
}
}
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