Skip to content

Commit

Permalink
fix(ios): make query timeout after 30s
Browse files Browse the repository at this point in the history
  • Loading branch information
alarm109 committed Feb 15, 2023
1 parent 6156fb7 commit a859c28
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions ios/RNHealthTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import HealthKit
@objc(RNHealthTracker)
class RNHealthTracker: NSObject {
private let healthStore: HKHealthStore = HKHealthStore()
private let QUERY_TIMEOUT_IN_SECONDS = 30.0

@objc static func requiresMainQueueSetup() -> Bool {
return true
Expand Down Expand Up @@ -286,7 +287,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down Expand Up @@ -344,7 +345,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down Expand Up @@ -404,7 +405,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 20) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down Expand Up @@ -471,7 +472,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down Expand Up @@ -535,7 +536,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down Expand Up @@ -680,6 +681,10 @@ class RNHealthTracker: NSObject {
) else { return }

healthStore.execute(sampleQuery)

DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(sampleQuery)
}
}

@objc public func getLatestDataRecord(
Expand Down Expand Up @@ -864,7 +869,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down Expand Up @@ -941,7 +946,7 @@ class RNHealthTracker: NSObject {

healthStore.execute(query)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) {
self.healthStore.stop(query)
}
}
Expand Down

0 comments on commit a859c28

Please sign in to comment.