Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jacobsapps/5871d0ddf60bd8a7169a015bc71190a3 to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/5871d0ddf60bd8a7169a015bc71190a3 to your computer and use it in GitHub Desktop.
webSocketService.publisher
.buffer(size: 1, prefetch: .keepFull, whenFull: .dropOldest)
.compactMap { data -> AuctionBid? in
try? decoder.decode(AuctionBid.self, from: data)
}
.scan([]) { (history: [AuctionBid], newBid) in
history + [newBid]
}
.receive(on: RunLoop.main)
.sink(receiveCompletion: { print($0) },
receiveValue: { bids in
withAnimation {
bidHistory = bids
highestBid = bids.last
timeRemaining = bids.last?.timeRemaining ?? 0
}
})
.store(in: &cancellables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment