Skip to content

Commit

Permalink
make EventStreamTask non-throwing
Browse files Browse the repository at this point in the history
nothing is awaiting the task so there's no pointer throwing an error, the best
we can do is return nil on the Flutter channel (which we do already)

This simplifies the code somewhat, we will ignore any errors and always remove
the task when the sequence completes or an error is thrown
  • Loading branch information
lhoward committed Nov 24, 2024
1 parent 1dc68d4 commit d8454e1
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 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 @@ -163,14 +163,8 @@ public final class FlutterEventChannel: _FlutterBinaryMessengerConnectionReprese
case "listen":
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
self._removeTask(id)
throw error
}
try? await self._run(for: stream, name: name)
self._removeTask(id)
}
_addTask(id, task)
envelope = FlutterEnvelope.success(nil)
Expand Down

0 comments on commit d8454e1

Please sign in to comment.