Skip to content

Commit

Permalink
Fix bufferingPolicy not passed in.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Jun 10, 2022
1 parent f79fc09 commit 4e4c747
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/sqlite/SQLiteWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public final class SQLiteWorkspace: Workspace {
public func subscribe<Element: Atom & Equatable>(
object: Element, bufferingPolicy: AsyncStream<Element>.Continuation.BufferingPolicy
) -> AsyncStream<Element> {
AsyncStream { continuation in
AsyncStream(bufferingPolicy: bufferingPolicy) { continuation in
let cancellable = self.subscribe(object: object) { object in
switch object {
case .deleted:
Expand All @@ -546,7 +546,7 @@ public final class SQLiteWorkspace: Workspace {
fetchedResult: FetchedResult<Element>,
bufferingPolicy: AsyncStream<FetchedResult<Element>>.Continuation.BufferingPolicy
) -> AsyncStream<FetchedResult<Element>> {
AsyncStream { continuation in
AsyncStream(bufferingPolicy: bufferingPolicy) { continuation in
let cancellable = self.subscribe(fetchedResult: fetchedResult) { fetchedResult in
continuation.yield(fetchedResult)
}
Expand Down
5 changes: 2 additions & 3 deletions src/tests/AsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,13 @@ class AsyncTests: XCTestCase {
MyGame.Sample.Monster.mana <= 50, orderBy: [MyGame.Sample.Monster.mana.ascending])
XCTAssertEqual(fetchedResult.count, 6)
let subscribeTask = Task { () -> FetchedResult<MyGame.Sample.Monster> in
var updateCount = 0
var updatedFetchedResult = fetchedResult
for await newFetchedResult in dflat.subscribe(
fetchedResult: fetchedResult, bufferingPolicy: .unbounded)
{
updatedFetchedResult = newFetchedResult
updateCount += 1
if updateCount == 4 {
if newFetchedResult.first(where: { $0.name == "name 3" }) == nil {
// We've deleted this one, that's the last mutation, exit.
break
}
}
Expand Down

0 comments on commit 4e4c747

Please sign in to comment.