Questions tagged [dispatch-queue]
231 questions
4
votes
1 answer
Applying filter to real time camera preview - Swift
I'm trying to follow the answer given here: https://stackoverflow.com/a/32381052/8422218 to create an app which uses the back facing camera and adds a filter, then displays it on the screen in real time
here is my code:
//
// …

nopassport1
- 1,821
- 1
- 25
- 53
3
votes
2 answers
Custom DispatchQueue quality of service
Is there a way to create a custom DispatchQueue quality of service with its own custom "speed"? For example, I want a QoS that's twice as slow as .utility.
Ideas on how to solve it
Somehow telling the CPU/GPU that we want to run the task every X…

Tamás Sengel
- 55,884
- 29
- 169
- 223
3
votes
2 answers
Why two different serial queue creating deadlock in swift?
I have one custom serial queue, in side this calling main queue synchronously. It's creating deadlock. As per my understanding both are independent queues so it should work and both (Step 3 and Step 5) synchronous block should execute. Can anyone…

Dipak
- 2,263
- 1
- 21
- 27
3
votes
2 answers
Does DispatchQueue run in its own thread?
I'm trying to understand how DispatchQueues really work and I'd like to know if this is safe to assume that DispatchQueues have their own managing thread ? For example let's take the serial queue. In my understanding - since it is serial the new…

Andre Liberty
- 707
- 1
- 9
- 17
3
votes
1 answer
Main Thread & Collectionview.reloadData()
I have a situation where the code change its collectionView data source then call reloadData() several times and i think this cause my app to crash due to the race condition as the data source change very fast, so I wrapped the snippet of code that…

Bathant Hegazy
- 549
- 4
- 16
3
votes
2 answers
How to properly use DispatchQueue.main.async?
I have a loop in my app that can take a few seconds to process.
I want the screen to dismiss immediately while the loop runs in the background.
Is this possible?
I've tried adding only the loop:
DispatchQueue.main.async {
for _ in…

BriScoLeg
- 105
- 1
- 9
3
votes
1 answer
Why i should use the NSManagedObjectContext's perform() and performAndWait() while i can use DispatchQueue.global
I have some confusion about run the CoreData code on the background queue.
There is some methods we can use to perform a CoreData code on the background thread using the NSManagedObjectContext.
viewContext.perform { /*some code will run on the…

Mohamed Mohsen
- 167
- 1
- 13
3
votes
1 answer
Playing instance of AVAudioPlayer from background thread sometimes fails
I am trying to play a sound from a background thread using an instance of an AVAudioPlayer in Swift 5. Most of the time, it will be successful. But once in a while the audio player fails to play a sound.
It appears as though calling play() twice, or…

star8163264
- 148
- 2
- 8
3
votes
1 answer
DispatchQueue.global(qos: .default) continues when app is backgrounded or screen locked, how to suspend?
Swift Newbie: porting Objective-C AppleHealth integration code to Swift that is invoked by Flutter/Dart. When I background or lock-screen the legacy Obj-C app, it pretty much immediately suspends all execution.
However the same behaviour doesn't…

Random Joe
- 69
- 6
3
votes
3 answers
Correct way to perform async operations sequentially
I need to perform an async operation for each element in an array, one at at time. This operation calls back on the main queue.
func fetchResults(for: array, completion: () -> Void) {
var results: [OtherObject]: []
let queue =…

Ashley Mills
- 50,474
- 16
- 129
- 160
3
votes
1 answer
Android: Dispatch queue
I am building an app that will make a web request whenever you scan a qr code. If you have internet available, making that request is easy. If we don't have internet, I want to put it onto a queue and make those requests whenever I have internet on…

Arham Akbar
- 41
- 1
- 4
3
votes
1 answer
Is it possible to create multiple DispatchQueue?
I'm not very much old with DispatchQueue things (including DispatchGroups, Qos etc.). And I have a concern right now.
It's like, I have a ViewController that is reused for Android's ViewPager UI. And in that VC, I have a TableView which reloads…
user10065208
3
votes
1 answer
serial Dispatch Queue will use only one thread?
I find that serial queue will use more than one thread to run async code.
Here's the test code in playground.
import Foundation
let q = DispatchQueue(label: "test")
q.async {
print("hi \(Thread.current)")
}
q.async {
print("hi…

simpzan
- 515
- 6
- 15
3
votes
1 answer
How to make a delay in a loop in SpriteKit?
I have made some search here and there but I didn't find (or understand) how to make a delay in a loop in SpriteKit.
This is the idea : I have some SKSpriteNodes sorted in an array and I want to display them on the screen, one every second. The…

Vincent
- 31
- 1
2
votes
2 answers
Why is this Swift Readers-Writers code causing deadlock?
I seem to have a classic solution for Readers-Writers problem in Swift using concurrent DispatchQueue with a barrier for writes. However, then I run my test code, it deadlocks.
Here's my wanna-be-thread-safe data structure:
class Container {
…

Alex
- 1,574
- 17
- 36