Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

immediateFire not work #52

Open
dourgulf opened this issue Aug 11, 2022 · 0 comments
Open

immediateFire not work #52

dourgulf opened this issue Aug 11, 2022 · 0 comments

Comments

@dourgulf
Copy link

for such testcase

    func test_throttleFirstImmediateFire() {
        let exp = expectation(description: "Run twice and call immediately")

        var value = 0
        let extractedExpr = Throttler(time: .milliseconds(500), immediateFire: true, {
            value += 1
        })
        self.throttle = extractedExpr

        self.throttle?.call()
        self.throttle?.call()
        self.throttle?.call()
        self.throttle?.call()
        self.throttle?.call()

        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
            if value == 2 {
                exp.fulfill()
            } else {
                XCTAssert(value == 2, "Failed to throttle, calls were not ignored.")
            }
        }

        self.wait(for: [exp], timeout: 1)
    }

expect value == 2, first time and second time after 500ms.
but, this test case failed,
I guess
queue.asyncAfter(deadline: dispatchTime, execute: callbackJob) was cancel by second call()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant