Skip to main content
12 events
when toggle format what by license comment
Mar 24, 2023 at 11:22 comment added DrMickeyLauer @Rob: I tried your code snippet and with Swift 5.8 as per Xcode 14.3, the tests are failing. E.g.: testDebouncer(): XCTAssertEqual failed: ("hel") is not equal to ("hello")
Dec 2, 2022 at 16:47 history edited Rob CC BY-SA 4.0
Really should use “async algorithms” implementation
Dec 2, 2022 at 13:04 comment added Martin Oh! Thanks so much for the detailed explanation @Rob! That makes sense to me now.
Dec 2, 2022 at 7:24 history edited Rob CC BY-SA 4.0
Async algorithms
Dec 1, 2022 at 19:50 comment added Rob @Martin - Because sendToServer was appending to value, and he never resets value, the final result of "old" is the final "o" of "hello" and the "ld" of "world". This is, IMHO, a very counter-intuitive example (you generally want to debounce/throttle network requests, not the user input). I was attempting to mirror the test in the question as closely as possible. But I have revised my answer with a more intuitive handling of debouncing/throttling network requests but not user input.
Dec 1, 2022 at 19:50 history edited Rob CC BY-SA 4.0
Debounce network requests, but the accumulation of user input
Dec 1, 2022 at 8:44 comment added Martin shouldn't that be case 1: XCTAssertEqual(value, "ld") in testDebouncer() ?
Jan 19, 2022 at 15:22 history edited Rob CC BY-SA 4.0
incorporate race comment from below
Jan 19, 2022 at 5:28 vote accept TruMan1
Jan 19, 2022 at 5:27 comment added Rob I would advise against that that “use non-isolated function to initiate an asynchronous isolated asynchronous task” technique because not only is it very misleading, but actors also feature reentrancy, and you introduce all sorts of unintended races, which is why I excised the pattern from my answer above.
Jan 18, 2022 at 14:13 comment added TruMan1 Thx for the review! Looks like bug reported for callAsFunction crash for actors: bugs.swift.org/browse/SR-15361, good catch. Regarding why nonisolated worked for my version is because I call Task inside so it becomes isolated again (I think?). But also doing it this way so the caller doesn't have to be in a concurrency/await state, anyone can call and forget it. Last thing, I still couldn't get the first 2 tests to pass in either of our versions (testThrottler and testDebouncer). I've struggled to understand if something is wrong with the limiter logic or the test itself.
Jan 18, 2022 at 4:19 history answered Rob CC BY-SA 4.0