Skip to content

immediateFire not work #52

@dourgulf

Description

@dourgulf

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions