Skip to content

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

Open
@CalebKierum

Description

@CalebKierum

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions