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

Timeout or way to cancel socketClient.once() so that .once() can be safely wrapped in a withCheckedContinuation swift async block #1507

Open
CalebKierum opened this issue Dec 12, 2024 · 0 comments

Comments

@CalebKierum
Copy link

CalebKierum commented Dec 12, 2024

Perhaps I am over-complicating things or missing some aspect of swift async that would make this work nicely.

However the present problem I have is that socket.once() does not have a timeout nor can I get it to "cancel"

See below an example where I am trying to wrap socket.once() into swift async and use withCheckedContinuation to safely wrap up the non swift async code but have no way to call the continuation after a timeout nor propagate the cancel downwards.

private func waitForPong(_ uuid: UUID, _ count: Int) async -> Bool {
        let pongReceived = await withCheckedContinuation { continuation in
            socket.once("pong") { _, _ in
                continuation.resume(returning: true)
            }
        }
        return pongReceived
    }

If you create a task and have it await on waitForPong it will wait indefinitely for that pong. Even if you cancel() the there is no way to get rid of your now stuck Task.

Even if I off or cancel it I do not get the handler needed for the NormalCallback

@CalebKierum CalebKierum changed the title Timeout or way to cancel socketClient.once() so that .once() can be safely wrapped in a withCheckedContinuation swift async block Timeout or way to cancel socketClient.once() so that .once() can be safely wrapped in a withCheckedContinuation swift async block Dec 12, 2024
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