@@ -301,6 +301,7 @@ public class FrequencyReader: Reader<[Double]> {
301
301
private var prev : ( samples: CFDictionary , time: TimeInterval ) ? = nil
302
302
303
303
private let measurementCount : Int = 4
304
+ private var isReading : Bool = false
304
305
305
306
private struct IOSample {
306
307
let group : String
@@ -320,7 +321,8 @@ public class FrequencyReader: Reader<[Double]> {
320
321
}
321
322
322
323
public override func read( ) {
323
- guard !self . eCoreFreqs. isEmpty && !self . pCoreFreqs. isEmpty, self . channels!= nil , self . subscription!= nil else { return }
324
+ guard !self . isReading, !self . eCoreFreqs. isEmpty && !self . pCoreFreqs. isEmpty, self . channels!= nil , self . subscription!= nil else { return }
325
+ self . isReading= true
324
326
let minECoreFreq = Double ( self . eCoreFreqs. min ( ) ?? 0 )
325
327
let minPCoreFreq = Double ( self . pCoreFreqs. min ( ) ?? 0 )
326
328
@@ -352,6 +354,7 @@ public class FrequencyReader: Reader<[Double]> {
352
354
let pFreq : Double = pCores. reduce ( 0 , { $0+ $1} ) / Double( self . measurementCount)
353
355
354
356
self . callback ( [ eFreq, pFreq] )
357
+ self . isReading= false
355
358
}
356
359
}
357
360
@@ -421,7 +424,12 @@ public class FrequencyReader: Reader<[Double]> {
421
424
422
425
for _ in 0 ..< self . measurementCount{
423
426
let milliseconds = UInt64 ( step) * 1_000_000
424
- try ? await Task . sleep ( nanoseconds: milliseconds)
427
+ do {
428
+ try await Task . sleep ( nanoseconds: milliseconds)
429
+ } catch {
430
+ if Task . isCancelled{ return [ ] }
431
+ continue
432
+ }
425
433
426
434
guard let next= self . getSample ( ) else { continue }
427
435