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

Try this, withTimeout seems not work #1

Open
King-Eternal opened this issue Dec 5, 2022 · 1 comment
Open

Try this, withTimeout seems not work #1

King-Eternal opened this issue Dec 5, 2022 · 1 comment

Comments

@King-Eternal
Copy link

King-Eternal commented Dec 5, 2022

`
func testAsync() async -> String {
var value = 0
for _ in 0...10_000_0000 {
value += 1
}
return "(value)"
}

    Task {
        do {
            let res = try await withTimeout(0.25) {

                await testAsync()
            }
            print(res)
        } catch {
            print(error)
        }
    }
    
  `
@alexito4
Copy link
Owner

What is the content of testAsync ?? Every async function needs to cooperate for this to work. Read https://alejandromp.com/blog/the-importance-of-cooperative-cancellation/

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

2 participants