Coder Social home page Coder Social logo

Comments (5)

Jeehut avatar Jeehut commented on May 18, 2024

The reason the callbacks are made in the main thread is that this library was written for cases where you need to import a (potentially) large CSV file and want to give the user some kind of progress feedback. That's what the onProgress and onFinish callbacks were designed for and since the UI should only be updated in the main thread, those blocks are called on the main thread.

I don't see any adverse effects except for the above mentioned UI changes when you would fork this and remove the main thread calls. If you want to ensure that you have an up-to-date framework, feel free to make your change in your fork additive (and non-breaking) so I can merge your changes via a Pull Request and we have optional support for explicitly defining the thread on which the callbacks should be called. I imagine something like this:

let importer = CSVImporter<[String]>(...)
importer.qosClass = .background
importer.startImporting(...).onProgress {
    // called in background thread
}.onFinish {
    // called in background thread
}

By default it would then still make the calls in the main thread, except for if you have defined a qosClass, then it would use a global DispatchQueue of the given qos class.

from csvimporter.

rodericj avatar rodericj commented on May 18, 2024

I think that's reasonable. I am importing a large CSV but I'd like to have all processing finished on the background thread where I import into my indexable data model. While I love your implementation I may end up rolling my own or using one of the other parsers. My need is slightly different than what you're addressing.

Thanks for getting back to me.

from csvimporter.

Jeehut avatar Jeehut commented on May 18, 2024

But the importing is done on a background thread and adding support for background threads in the callbacks is not a complex task, if you're not sure how to add that feature yourself I can do that. Others may need the feature, too.

from csvimporter.

Jeehut avatar Jeehut commented on May 18, 2024

I just implemented such a feature and released version 1.6.0 with it included. See the end of the Asynchronous with Callbacks section in the README for usage. Your requested behavior should now be possible @rodericj. If you have any more questions feel free to ask.

Closing this.

from csvimporter.

Jeehut avatar Jeehut commented on May 18, 2024

Note that I've also just added a synchronously working import method and released version 1.7.0 with it. Refer to the docs here.

from csvimporter.

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.