Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/065e6349-8e2a-403b-b588-067161f260fd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "065e6349-8e2a-403b-b588-067161f260fd",
"type": "bugfix",
"description": "Correctly handle sequential calls to `SingleFlightGroup`"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SingleFlightGroup<T> {
public suspend fun singleFlight(block: suspend () -> T): T {
mu.lock()
val job = inFlight
if (job != null) {
if (job?.isActive == true) {
waitCount++
mu.unlock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,14 @@ class SingleFlightGroupTest {
}
}
}

@Test
fun testSequential() = runTest {
val group = SingleFlightGroup<String>()
val first = group.singleFlight { "Foo" }
assertEquals("Foo", first)

val second = group.singleFlight { "Bar" }
assertEquals("Bar", second)
}
}
Loading