Skip to content

Commit

Permalink
Clear the cache for the stream handler once a listener sinks it
Browse files Browse the repository at this point in the history
  • Loading branch information
trueb2 committed Dec 9, 2021
1 parent 42669de commit a950049
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ios/Classes/CachingStreamHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class CachingStreamHandler<T>: NSObject, FlutterStreamHandler {
private let cacheSemaphore = DispatchSemaphore(value: 1)

func add(_ taskId: String, _ value: T) {
cacheSemaphore.wait()
cache[taskId] = value
cacheSemaphore.signal()

if let sink = eventSink {
sink(value)
} else {
cacheSemaphore.wait()
cache[taskId] = value
cacheSemaphore.signal()
}
}

Expand All @@ -35,6 +35,7 @@ class CachingStreamHandler<T>: NSObject, FlutterStreamHandler {
for cacheEntry in cache {
events(cacheEntry.value)
}
cache = [:]
cacheSemaphore.signal()

self.eventSink = events
Expand Down

0 comments on commit a950049

Please sign in to comment.