Resource TaskChain - Proper Async Operations and more!

Discussion in 'Spigot Plugin Development' started by Aikar, Oct 30, 2016.

  1. Random hiccups happen, so 19.98 is perfectly normal for any server.

    Sure, https://paypal.me/empireminecraft - this is my personal company, makes it easier for me to track extra income to pay the taxes on it. (donation's are only tax-free if it's to a non profit company :p)
     
  2. foncused

    Moderator Patron

    Yeah I figured as much but thought I would ask anyway since I only noticed the drop immediately following the quit event (and as an extension was then thinking what would happen if a bunch of people leave at the same time). :p
    I know such a small drop is nothing to really worry about - my OCD more or less wanted to know. Thanks again!
    Thanks, sir.
     
  3. @Aikar Does this work for bungeecord plugins as well?
     
  4. electronicboy

    IRC Staff

    Bungeecord doesn't have the concept of a main thread, so taskchain is pretty much irrelevant for it
     
    • Informative Informative x 1
  5. Been a while, still very useful to use, so bump!
     
    • Agree Agree x 2
  6. What's different with CompletableFuture ?
     
  7. MiniDigger

    Supporter

    Taskchain utilises callbacks like futures, but the point of taskchain is to easily switch between the main thread and an async thread. Imagine calling a web-api async, then doing something with the Bukkit API with the result and then posting something to a web api async again. Taskchain helps you to not get lost in callback hell
     
  8. CompletableFuture also provides switching between threads.
     
  9. TaskChain also makes it much easier to return to the main thread later, removes a decent amount of fluff and callback hell potential. If you prefer CompletableFutures that's fine, but it's designed around entering and exiting the main thread without having to use the clunkier methods Bukkit provides. Bukkit doesn't exactly make it easy to avoid callback hell, there's been no update to the scheduler API in a long time.
     
  10. There was the proposed Consumer syntax availability that was merged a couple of months ago. Unrelated to switching around threads in a threaded environment, but figured I'd point this out.
     
    • Informative Informative x 1
    • Useful Useful x 1
  11. Yeah, that was nice, good point. My main issue lies with BukkitScheduler#callSyncMethod requiring a decent bit of boilerplate to handle. Honestly, changing the return from a Future to a CompletableFuture would make TaskChain largely unnecessary, though I do also need its other features from time to time.
     
  12. And so it is possible to chain bukkit task together too.

    Switching threads in CF's is kind of misleading in a bukkit terminology sense because your code says "thenApplyAsync(cb, this.someMainThreadExecutor)"

    That async word when you are wanting to run something sync is kinda confusing...

    And it requires you setting up a custom executor that dispatches Sync Tasks to the Bukkit Scheduler.

    Guess what TaskChain does? All that for you...

    TC is just a clean API to do what you need to do without the boilerplate it takes do it it otherwise.

    Sure if you do the custom executor to return to main. But essentially talking about solving a problem that already has a light weight solution.

    TC takes all the code you would have to write to do all this logic yourself, and provides it as an abstract library for you.


    Also, TC has concurrency utilities not found in futures to help ensure 2 related chains are not happening concurrently.
     
    #112 Aikar, Apr 1, 2020
    Last edited: Apr 1, 2020