Giter Club home page Giter Club logo

Comments (12)

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

Hi @marinofaggiana, thanks 😄
What kind of examples do you need?

If you are looking for a ConcurrentOperation subclass, you can take a look at the SynchronousOperation subclass implementation.

Let me know if you need anything else!

from queuer.

marinofaggiana avatar marinofaggiana commented on May 18, 2024

Hi @FabrizioBrancati, tanks for your response, with semaphore? I need of a maxConcurrentOperationCount = 5 but I don't understand your implementation... can you explain a small example for this ?

from queuer.

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

You can find an example on the README or inside the SemaphoreTests.swift file in the Tests folder.

If it's not enough, what's your use case?

from queuer.

marinofaggiana avatar marinofaggiana commented on May 18, 2024

Thanks @FabrizioBrancati I need e.g. of read 1000 files with a async func e.g.

func download (filename: string, completion: @escaping (_ errorCode: Int) -> ())

but with max 5 download in execution, we already have a class for this but I am interested to try with you lib if can streamline the code :-)

from queuer.

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

Why do you need a semaphore?

You can just create 1000 ConcurrentOperations and adding them to a queue by setting maxConcurrentOperationCount property to 5.
They will be executed by 5 until the end.
If you want, you can subclass ConcurrentOperation to create your custom operation to be added to the queue.

from queuer.

marinofaggiana avatar marinofaggiana commented on May 18, 2024

yes, of better NO, we have look you code and now is clear. thanks

from queuer.

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

Are you sure?
Can I close the issue? 😄

from queuer.

marinofaggiana avatar marinofaggiana commented on May 18, 2024

Can be improved?

import Foundation
import Queuer

@objc class NCOperationQueue: NSObject {
    @objc public static let shared: NCOperationQueue = {
        let instance = NCOperationQueue()
        return instance
    }()
    
    let downloadQueue = Queuer(name: "downloadQueue", maxConcurrentOperationCount: 5, qualityOfService: .default)
    
    @objc func download(fileName: String) {
        downloadQueue.addOperation(NCOperationDownload.init(filename: filename))
    }
}

class NCOperationDownload: ConcurrentOperation {
   
    private var filename: String
    
    init(filename: String) {
        self.filename = filename
    }
    
    override func start() {
        NCNetworking.shared.download(filename: self.filename) { (_) in
            self.finish()
        }
    }
}

from queuer.

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

You can take a look at the RequestOperation that was implemented in the first version of Queuer.

There are a lot of ways to improve your code 😉

from queuer.

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

Did you take a look at the RequestOperation source file?

from queuer.

FabrizioBrancati avatar FabrizioBrancati commented on May 18, 2024

Hi @marinofaggiana news about this? 😄

from queuer.

marinofaggiana avatar marinofaggiana commented on May 18, 2024

Hi @FabrizioBrancati sorry for the long time, all ok, we can close this.

from queuer.

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.