Skip to content

Commit 38d976f

Browse files
fix: potential race condition in callback (#75)
* fix: potential race condition in callback * fix: potential race condition in callback
1 parent 65a4806 commit 38d976f

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

.github/workflows/harness-android.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@ on:
5555
paths:
5656
- ".github/workflows/harness-android.yml"
5757
- "example/android/**"
58-
- "package/android/**"
59-
- "package/ios/**"
60-
- "package/src/**"
61-
- "package/nitrogen/**"
58+
- "packages/react-native-nitro-fetch/android/**"
59+
- "packages/react-native-nitro-text-decoder/android/**"
60+
- "packages/react-native-nitro-text-decoder/ios/**"
61+
- "packages/react-native-nitro-websockets/android/**"
62+
- "packages/react-native-nitro-websockets/ios/**"
63+
- "packages/react-native-nitro-fetch/src/**"
64+
- "packages/react-native-nitro-text-decoder/src/**"
65+
- "packages/react-native-nitro-websockets/src/**"
66+
- "packages/react-native-nitro-fetch/nitrogen/**"
67+
- "packages/react-native-nitro-text-decoder/nitrogen/**"
68+
- "packages/react-native-nitro-websockets/nitrogen/**"
6269
- "**/bun.lock"
6370
- "**/react-native.config.js"
6471
- "example/__tests__/**"

.github/workflows/harness-ios.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ on:
4747
paths:
4848
- ".github/workflows/harness-ios.yml"
4949
- "example/ios/**"
50-
- "package/ios/**"
51-
- "package/src/**"
52-
- "package/nitrogen/**"
50+
- "packages/react-native-nitro-fetch/ios/**"
51+
- "packages/react-native-nitro-text-decoder/ios/**"
52+
- "packages/react-native-nitro-websockets/ios/**"
53+
- "packages/react-native-nitro-fetch/src/**"
54+
- "packages/react-native-nitro-text-decoder/src/**"
55+
- "packages/react-native-nitro-websockets/src/**"
56+
- "packages/react-native-nitro-fetch/nitrogen/**"
57+
- "packages/react-native-nitro-text-decoder/nitrogen/**"
58+
- "packages/react-native-nitro-websockets/nitrogen/**"
5359
- "**/Podfile.lock"
5460
- "**/*.podspec"
5561
- "**/bun.lock"

packages/react-native-nitro-fetch/ios/FetchCache.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,13 @@ final class FetchCache {
2525
}
2626

2727
static func complete(_ key: String, with result: Result<NitroResponse, Error>) {
28-
var callbacks: [(Result<NitroResponse, Error>) -> Void] = []
29-
queue.sync {
30-
callbacks = pending[key] ?? []
31-
}
3228
queue.async(flags: .barrier) {
33-
pending.removeValue(forKey: key)
29+
let callbacks = pending.removeValue(forKey: key) ?? []
3430
if case let .success(resp) = result {
3531
results[key] = CachedEntry(response: resp, timestampMs: Int64(Date().timeIntervalSince1970 * 1000))
3632
}
33+
callbacks.forEach { $0(result) }
3734
}
38-
callbacks.forEach { $0(result) }
3935
}
4036

4137
static func getResultIfFresh(_ key: String, maxAgeMs: Int64) -> NitroResponse? {

0 commit comments

Comments
 (0)