GithubHelp home page GithubHelp logo

Comments (2)

ra1popov avatar ra1popov commented on June 8, 2024

I understood what the problem is..
In my case, the current thread was not blocked because my task did not arrive to the queue at the time of the call waitUntilAllOperationsAreFinished method.

The waitUntilAllOperationsAreFinished method description:
Blocks the current thread until all the receiver’s queued and executing operations finish executing.
https://developer.apple.com/documentation/foundation/operationqueue/1407971-waituntilalloperationsarefinishe

We can use NSCondition for lock, but I chose another solution, example here:

    let amount = 255
   
    let latch = CountDownLatch(count: amount)
    
    for i in 0 ..< amount {
        let job = FindDeviceJob(id: i, queue: "queue_\(i / 25)")
        queueManager.add(job: job)
            .subscribe(onCompleted: {
                print("queue created: \(i)")
                latch.countDown()
            }, onError: { error in
                print(error)
            }).disposed(by: disposeBag)
    }
    
    print("wait1")
    latch.await() // we are waiting for all tasks to be added to our queue via the CountDownLatch pattern ( https://github.com/uber/swift-concurrency.git )
    
    print("wait2")
    queueManager.waitUntilAllOperationsAreFinished() // and we are waiting for all tasks to be completed

    print("finish")

result:
queue created: 0..<n
wait1
queue created: 0..<n (a tasks added to our queue after the "wait1" message)
wait2
complete 0..<n
finish

from swiftqueue.

stale avatar stale commented on June 8, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from swiftqueue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.