Skip to content

Commit 6f94c6a

Browse files
authored
fix: correctly handle sequential calls to SingleFlightGroup (#1251)
1 parent 4b0df67 commit 6f94c6a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "065e6349-8e2a-403b-b588-067161f260fd",
3+
"type": "bugfix",
4+
"description": "Correctly handle sequential calls to `SingleFlightGroup`"
5+
}

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/util/SingleFlightGroup.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SingleFlightGroup<T> {
3030
public suspend fun singleFlight(block: suspend () -> T): T {
3131
mu.lock()
3232
val job = inFlight
33-
if (job != null) {
33+
if (job?.isActive == true) {
3434
waitCount++
3535
mu.unlock()
3636

runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/util/SingleFlightGroupTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ class SingleFlightGroupTest {
109109
}
110110
}
111111
}
112+
113+
@Test
114+
fun testSequential() = runTest {
115+
val group = SingleFlightGroup<String>()
116+
val first = group.singleFlight { "Foo" }
117+
assertEquals("Foo", first)
118+
119+
val second = group.singleFlight { "Bar" }
120+
assertEquals("Bar", second)
121+
}
112122
}

0 commit comments

Comments
 (0)