Skip to content

Commit

Permalink
issue(123867): replaced Dispatch to MainActor.run
Browse files Browse the repository at this point in the history
  • Loading branch information
feduke-nukem committed Dec 23, 2024
1 parent 1b22130 commit 71ba017
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/pigeon/example/app/ios/Runner/Messages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class PigeonError: Error {
var localizedDescription: String {
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
}
}
}

private func wrapResult(_ result: Any?) -> [Any?] {
Expand Down Expand Up @@ -234,11 +234,11 @@ class ExampleHostApiSetup {
Task {
do {
let result = try await api.sendMessageModernAsync(message: messageArg)
DispatchQueue.main.async {
await MainActor.run() {
reply(wrapResult(result))
}
} catch {
DispatchQueue.main.async {
await MainActor.run() {
reply(wrapError(error))
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1613,10 +1613,10 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
indent.writeln('Task {');
indent.inc();
}
void wrapDispatchMain(void Function() body) {
void wrapMainActorRun(void Function() body) {
if (asynchronousType.isModern) {
return indent.writeScoped(
'DispatchQueue.main.async {',
'await MainActor.run() {',
'}',
body,
);
Expand All @@ -1629,16 +1629,16 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
indent.addScoped('{', '}', () {
if (returnType.isVoid) {
indent.writeln(call);
wrapDispatchMain(() => indent.writeln('reply(wrapResult(nil))'));
wrapMainActorRun(() => indent.writeln('reply(wrapResult(nil))'));
} else {
indent.writeln('let result = $call');
wrapDispatchMain(
wrapMainActorRun(
() => indent.writeln('reply(wrapResult(result))'),
);
}
}, addTrailingNewline: false);
indent.addScoped(' catch {', '}', () {
wrapDispatchMain(() => indent.writeln('reply(wrapError(error))'));
wrapMainActorRun(() => indent.writeln('reply(wrapError(error))'));
});
}
});
Expand Down

0 comments on commit 71ba017

Please sign in to comment.