Skip to content

[WIP][Concurrency] Optimize Void task group, to not store completed tasks #62246

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

Closed
wants to merge 1 commit into from

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Nov 25, 2022

This optimization work is to enable "infinite" task groups which just keep adding tasks "forever" but don't really need child task return values - for example, when implementing an RPC or web server, one might want to use a task group in order to stay inside structured concurrency for benefits of efficiency, task-local inheritance and canceling all in-flight rpcs when the server is cancelled.

Naively trying to handle such server case with:

    try await withThrowingTaskGroup(of: Void.self) { group in
        for try await query in dnsQuerySequence {
            group.addTask {
                handleQuery(query)
            }
        }
    }

--

Revision 2:

    try await withThrowingTaskGroup(of: Void.self, discardResults: true) { group in
        for try await query in dnsQuerySequence {
            group.addTask {
                handleQuery(query)
            }
            group.next() // always `nil`
        }
    }

Resolves rdar://101965913

@ktoso ktoso added concurrency Feature: umbrella label for concurrency language features swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal and removed swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal labels Nov 25, 2022
@ktoso ktoso closed this Dec 2, 2022
@ktoso
Copy link
Contributor Author

ktoso commented Dec 2, 2022

Superseeded by #62361

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant