Giter Club home page Giter Club logo

Comments (14)

czyzby avatar czyzby commented on May 22, 2024

@kotcrab Sweet. LibGDX HttpResponse implementation is not thread-safe and does not care if the underlying connection was closed, silently ignoring all exceptions. Here I was, wondering why my implementation of asynchronous HTTP requests always returns empty content - I debugged LibGDX code and now I'm surprised it even works in the first place.

from ktx.

czyzby avatar czyzby commented on May 22, 2024

@sreich @kotcrab How should I call the most commonly used method that gives you access to KTX coroutines context and allows to execute code on the main rendering thread? onMainThread, execute?

from ktx.

kotcrab avatar kotcrab commented on May 22, 2024

No idea. execute is too vague in my opinion. onMainThread or onGdxThread is ok-ish. I probably like most postRunnable, same as Gdx.app.postRunnable. Maybe just post but that seems vague if it's a global method.

from ktx.

czyzby avatar czyzby commented on May 22, 2024

postRunnable might be misleading, as coroutine can be executed on the same thread right after you start it, and it can create more than a single task objects under the hood. onMainThread isn't ideal either, as your coroutine might never do anything significant on the main thread. Maybe something more explicit like gdxCoroutine or ktxCoroutine?

The official method for creating coroutines with a context is launch. Our method would basically be a convenience wrapper over launch(KtxAsync). Any particular names with launch sound good?

from ktx.

kotcrab avatar kotcrab commented on May 22, 2024

I see. Nothing really strikes my mind though. I guess something like ktxAsync is not ideal either?

from ktx.

czyzby avatar czyzby commented on May 22, 2024

Not ideal, but simple and obvious. Not only does it match the module name, but also does not suggest where the code is executed (onMainThread) - only that it can be executed asynchronously. It's so trivial to add such method or simply use KtxAsync context directly with launch, that I don't think ktxAsync method will be harmful.

from ktx.

yhslai avatar yhslai commented on May 22, 2024

I personally +1 for onMainThread because when one use this kind of behavior he has to be aware of which thread the tasks will be executed.

Or onNextFrame, maybe? "Frame" sort of implies the thread that can render frames, a.k.a. main thread. Just my 2 cents.

from ktx.

czyzby avatar czyzby commented on May 22, 2024

But that's the thing: it does not have to be executed on the main thread. If you're using coroutines in the first place, chances are half of the instructions will be executed elsewhere. Only the processing of async operations results and non-suspending methods are invoked on the rendering thread. It might give you a false impressions that time consuming methods will block your rendering.

onMainThread {
  val httpResponse = httpRequest(url = "example.com", method = "GET") // Net executor.
  delay(1) // Timer.
  val result = asynchronous { someTask() } // Context's AsyncExecutor. 
}

from ktx.

sreich avatar sreich commented on May 22, 2024

Only the processing of async operations results and non-suspending methods are invoked on the rendering thread

I don't think you meant to say "non suspending methods". Suspending methods can be on any thread including the render thread and it can be useful to use them on the rendering thread to mask state.

Or am I misunderstanding here?

from ktx.

czyzby avatar czyzby commented on May 22, 2024

That's right, I oversimplified. I should have said non-suspending methods and suspending methods that can be executed on the main thread. KtxAsync context always tries to execute everything on the main rendering thread, besides the obvious cases where the actual work is delegated to other threads.

from ktx.

czyzby avatar czyzby commented on May 22, 2024

@kotcrab @sreich @raincole @MrPlow442 Can you take a look at the new module implementation and API? #57 I want your approval before merging and releasing this.

from ktx.

yhslai avatar yhslai commented on May 22, 2024

I'm heading for ludum dare this weekend. If no one else does I can help review it next week.

from ktx.

czyzby avatar czyzby commented on May 22, 2024

It's OK. Good luck. ; )

from ktx.

czyzby avatar czyzby commented on May 22, 2024

@kotcrab Thanks for the #57 code review. There's already a lot of changes since the last version, so I'm going to release 1.9.6-b2 now and move KTX to the new repository. Coroutines-based asset loader is postponed to the next release.

from ktx.

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.