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

Best practice in multi-thread app #37

Open
everwanna opened this issue Jan 23, 2019 · 1 comment
Open

Best practice in multi-thread app #37

everwanna opened this issue Jan 23, 2019 · 1 comment

Comments

@everwanna
Copy link

My app have a dispatchQ(DispatchQueue) for network requests and most other operations, and some other queues for heavy computing. I use PromiseKit like this,

    fetchData().then { objects in
        let tasks = objects.map { calculate($0 }
        return when(fulfilled: tasks)
    }.done {
    }.catch { error in
    }

PromiseKit is simple, I just use promise to replace those callbacks. Now I try to use AwaitKit, but soon I find out that await blocks current queue. dispatchQ can never be blocked because while waiting for network responses, the app might doing other small tasks in dispatchQ. I try to create awaitQ for waiting tasks like this,

    let awaitQ = DispatchQueue(label: "await")
    awaitQ.ak.async {
         let objects = try await(fetchData())
         let tasks = let tasks = objects.map { calculate($0 }
         try await(when(fulfilled: tasks))
    }

However, because dispatchQ have other tasks, awaitQ will still be blocked while waiting for one task. I will try to use DispatchQueue.global(qos: .userInitiated) to start more threads for waiting.

So, what is the best practice for app like this? Is it OK to start lots of threads for await?

@everwanna
Copy link
Author

Thanks in advance!

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