Skip to content

Commit

Permalink
y
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 24, 2024
1 parent 8a3f66b commit 398bf16
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions Sources/FlutterSwift/Channel/FlutterEventChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class FlutterEventChannel: _FlutterBinaryMessengerConnectionReprese
public let codec: FlutterMessageCodec
public let priority: TaskPriority?

private typealias EventStreamTask = Task<(), Error>
private typealias EventStreamTask = Task<Void, Never>

private let _connection: ManagedAtomic<FlutterBinaryMessengerConnection>
private let tasks: ManagedCriticalState<[String: EventStreamTask]>
Expand Down Expand Up @@ -169,28 +169,21 @@ public final class FlutterEventChannel: _FlutterBinaryMessengerConnectionReprese
debugPrint("*** listen name \(name) id \(id) args \(call.arguments)")
let stream = try await onListen(call.arguments)
let task = EventStreamTask(priority: priority) {
do {
try await self._run(for: stream, name: name)
} catch {
// at this point the task either ended normally or was cancelled;
// remove it from the task dictionary so that we don't leak tasks
debugPrint("*** removing task for \(id) after error \(error)")
self._removeTask(id)
throw error
}
try? await self._run(for: stream, name: name)
debugPrint("*** task finished of its own accord")
self._removeTask(id)
}
_addTask(id, task)
envelope = FlutterEnvelope.success(nil)
case "cancel":
debugPrint("*** cancel name \(name) id \(id) args \(call.arguments)")
_cancelTask(id)
do {
try await onCancel?(call.arguments)
envelope = FlutterEnvelope.success(nil)
} catch let error as FlutterError {
envelope = FlutterEnvelope.failure(error)
}
_cancelTask(id)
debugPrint("*** cancelled task for \(id)")
default:
envelope = nil
Expand Down

0 comments on commit 398bf16

Please sign in to comment.