You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My device is M1 Macbook Air. I tested it in Swift Playground, but the result does not match the timing diagram. I think the time of the result in the third row is drawn in the wrong place. All codes and results are as follows:
import Foundation
import Combine
letbounces:[(Int,TimeInterval)]=[(1,10),(2,20),(3,80),(4,90),(5,150),(6,160)]varstartTime=Date().timeIntervalSince1970
letsubject=PassthroughSubject<Int,Never>()varcancellable= subject
.throttle(for:.seconds(50), scheduler:RunLoop.main, latest:true).sink{ index inletoffset=Date().timeIntervalSince1970 - startTime
print("Received index \(index) at \(offset)")}forbouncein bounces {DispatchQueue.main.asyncAfter(deadline:.now()+ bounce.1){
subject.send(bounce.0)}}
Received index 1 at 10. 297373294830322
Received index 2 at 60. 29852819442749
Received index 4 at 110. 29963707923889
Received index 6 at 164. 99856996536255
import Foundation
import Combine
letbounces:[(Int,TimeInterval)]=[(1,10),(2,20),(3,80),(4,90),(5,150),(6,160)]varstartTime=Date().timeIntervalSince1970
letsubject=PassthroughSubject<Int,Never>()varcancellable= subject
.throttle(for:.seconds(50), scheduler:RunLoop.main, latest:false).sink{ index inletoffset=Date().timeIntervalSince1970 - startTime
print("Received index \(index) at \(offset)")}forbouncein bounces {DispatchQueue.main.asyncAfter(deadline:.now()+ bounce.1){
subject.send(bounce.0)}}
Received index 1 at 10. 309597969055176
Received index 2 at 60 .30997681617737
Received index 3 at 110. 31065487861633
Received index 5 at 164 .84435486793518
import Foundation
import Combine
letbounces:[(Int,TimeInterval)]=[(1,10),(2,20),(3,60),(4,70),(5,110),(6,120)]varstartTime=Date().timeIntervalSince1970
letsubject=PassthroughSubject<Int,Never>()varcancellable= subject
.debounce(for:.seconds(50), scheduler:RunLoop.main).sink{ index inletoffset=Date().timeIntervalSince1970 - startTime
print("Received index \(index) at \(offset)")}forbouncein bounces {DispatchQueue.main.asyncAfter(deadline:.now()+ bounce.1){
subject.send(bounce.0)}}
Received index 6 at 171 .00314784049988
import Foundation
import Combine
letbounces:[(Int,TimeInterval)]=[(1,10),(2,20),(5,110),(6,120)]varstartTime=Date().timeIntervalSince1970
letsubject=PassthroughSubject<Int,Never>()varcancellable= subject
.debounce(for:.seconds(50), scheduler:RunLoop.main).sink{ index inletoffset=Date().timeIntervalSince1970 - startTime
print("Received index \(index) at \(offset)")}forbouncein bounces {DispatchQueue.main.asyncAfter(deadline:.now()+ bounce.1){
subject.send(bounce.0)}}
Received index 2 at 71. 99511885643005
Received index 6 at 170 .99344301223755
The text was updated successfully, but these errors were encountered:
My device is M1 Macbook Air. I tested it in Swift Playground, but the result does not match the timing diagram. I think the time of the result in the third row is drawn in the wrong place. All codes and results are as follows:
Received index 1 at 10. 297373294830322
Received index 2 at 60. 29852819442749
Received index 4 at 110. 29963707923889
Received index 6 at 164. 99856996536255
Received index 1 at 10. 309597969055176
Received index 2 at 60 .30997681617737
Received index 3 at 110. 31065487861633
Received index 5 at 164 .84435486793518
Received index 6 at 171 .00314784049988
Received index 2 at 71. 99511885643005
Received index 6 at 170 .99344301223755
The text was updated successfully, but these errors were encountered: