Skip to content

Commit 6b02dfb

Browse files
committed
fix: Finish the continuation and await the consumtion of the stream
1 parent 403f480 commit 6b02dfb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+Index.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ extension WorkspaceDocument.SearchState {
2525
}
2626

2727
let (progressStream, continuation) = AsyncStream<Double>.makeStream()
28+
2829
// Dispatch this now, we want to continue after starting to monitor
29-
Task { await self.monitorProgressStream(progressStream, activityId: activity.id) }
30+
let monitorTask = Task {
31+
await self.monitorProgressStream(progressStream, activityId: activity.id)
32+
}
3033

3134
Task.detached {
3235
let filePaths = self.getFileURLs(at: url)
@@ -53,6 +56,8 @@ extension WorkspaceDocument.SearchState {
5356
}
5457
}
5558

59+
continuation.finish()
60+
await monitorTask.value // Await monitor to finish draining the stream
5661
asyncController.index.flush()
5762

5863
await MainActor.run {

CodeEditTests/Features/Documents/WorkspaceDocument+SearchState+FindAndReplaceTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ final class FindAndReplaceTests: XCTestCase {
9999
// IMPORTANT:
100100
// This is only a temporary solution, in the feature a file watcher would track the file update
101101
// and trigger a index update.
102-
Task {
103-
await searchState.addProjectToIndex()
104-
}
102+
await searchState.addProjectToIndex()
105103
let startTime = Date()
106104
while searchState.indexStatus != .done {
107105
try? await Task.sleep(nanoseconds: 100_000_000)

0 commit comments

Comments
 (0)