Skip to content

Add "reset timeout" variants #2

@gregcotten

Description

@gregcotten

Sometimes you just wanna reset the timeout timer if forward progress is made - I think this could be a great feature! Probably just some sort of closure passed to to the caller's async body, something like:

public func withThrowingResettableTimeout<T>(
    isolation: isolated (any Actor)? = #isolation,
    seconds: TimeInterval,
    body: (_ resetTimeout: () -> Void) async throws -> sending T
)

my particular use case would be something like (using FlyingSocks)

try await withThrowingResettableTimeout(seconds: 90) { resetTimeout in
    for try await message in socket.messages {
        resetTimeout()
        let response = try await handleSocketMessage(message.payload)
        try await socket.write(response)
    }
}

try? socket.close()

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