Add Scheduler#143
Conversation
olijeffers0n
left a comment
There was a problem hiding this comment.
I’m assuming this is still a WIP due to it ending abruptly and it being a draft PR, but here are a couple comments.
…le` and `Consumer<BukkitTask>`
|
A large part of the scheduler is being able to do things off the main thread. But this is barely explained in the PR. Is that intentional? Cause I feel like talking about "async" here makes a lot of sense. |
|
@Machine-Maker do you mean sth like explain the definition of sync and async in the scheduler's case? atm the plan would be to add quite a few different sections with different examples for delayed, repeating, both sync and async, stuff like cancelling a repeating task some time later and the PR is WIP like Ollie said |
|
Yeah, I think the concept of "async" isn't very well understood, along with its limitations when interacting with "world state". But sounds like you have plans, I just think in addition to example sections, there should be a blurb on what "async" means in this context. You have async to the main thread, but also async in a general context, means smth like on a different thread than where this code is currently running. |
|
Yep, as MM says explaining the concept behind the event loop and the pros/cons async is vital. I think the page name could be better in the sidebar. Even if it is just “The Scheduler” it would be better as just “Scheduler” looks weird IMO. |
|
@Machine-Maker I assume the BukkitScheduler executes the async tasks at the start/end of a tick (on separate threads) therefore is still somewhat affected if mspt exceeds 50ms, and your own |
|
@olijeffers0n wanna elaborate? Not sure I understood what you mean
|
|
Waiting for any suggestions, some criticism, etc. since I'm somewhat out of ideas for this; also making ready to review since IMHO asynchronous tasks examples are not really needed since that would be just repeating the synchronous examples with different method names |
|
Looks good, is it worth mentioning bukkit runnables? |
|
All scheduler methods that take Maybe could add it to the part about actually implementing |
| server.broadcast(Component.text("Hello, World!")); | ||
| }, 10 * 20, 5 * 20); | ||
|
|
||
| scheduler.runTaskLater(plugin, () -> task.cancel(), TimeUnit.MINUTES.toSeconds(10) * 20); |
There was a problem hiding this comment.
This is kind of dank, it should refer back to using the consumer or extending bukkitrunnable and deciding in the task when to cancel itself
There was a problem hiding this comment.
Not sure that's what you meant but changed
|
Gonna get to it soon |
olijeffers0n
left a comment
There was a problem hiding this comment.
Looks like its pretty much there, just a few suggestions really.
| slug: /dev/scheduler | ||
| --- | ||
|
|
||
| # Task Scheduler |
There was a problem hiding this comment.
Why is the page called task scheduler if you immediately refer to it with the BukkitScheduler name. Maybe just name the page "The Bukkit Scheduler" or something along those lines?
There was a problem hiding this comment.
I'd prefer something like Scheduling tasks over including Bukkit in the name
|
|
||
| # Task Scheduler | ||
|
|
||
| The `BukkitScheduler` can be used to schedule your code to be run later or run it repeatedly. |
There was a problem hiding this comment.
| The `BukkitScheduler` can be used to schedule your code to be run later or run it repeatedly. | |
| The `BukkitScheduler` can be used to schedule your code to be run later or repeatedly. |
| - your plugin's instance, | ||
| - the code to run, either with a `Runnable` or `Consumer<BukkitTask>`, | ||
| - the delay in ticks before the task should run, | ||
| - if you're scheduling a repeating task - the period in ticks between each execution of the task. |
There was a problem hiding this comment.
| - your plugin's instance, | |
| - the code to run, either with a `Runnable` or `Consumer<BukkitTask>`, | |
| - the delay in ticks before the task should run, | |
| - if you're scheduling a repeating task - the period in ticks between each execution of the task. | |
| - Your plugin's instance, | |
| - The code to run, either with a `Runnable` or `Consumer<BukkitTask>`, | |
| - The delay in ticks before the task should run for the first time, | |
| - If you're scheduling a repeating task - the period in ticks between each execution of the task. |
There was a problem hiding this comment.
Think of it as a long sentence, hence the commas and the period at the end,
will add for the first time
| plugin, | ||
| // Lambda: | ||
| () -> { | ||
| this.plugin.getServer().broadcast(Component.text("Hello, World!")); | ||
| }, | ||
| // End of the lambda | ||
| 20); |
There was a problem hiding this comment.
| plugin, | |
| // Lambda: | |
| () -> { | |
| this.plugin.getServer().broadcast(Component.text("Hello, World!")); | |
| }, | |
| // End of the lambda | |
| 20); | |
| plugin, /* Lambda: */ () -> { | |
| this.plugin.getServer().broadcast(Component.text("Hello, World!")); | |
| }, /* End of the lambda */ 20); |
Keeps it styled the same as the next example and looks cleaner
|
|
||
| ```java | ||
| scheduler.runTaskTimer(plugin, /* Lambda: */ task -> { | ||
| if(this.entity.isDead()) { |
There was a problem hiding this comment.
Missing a space between if and (
|
succeeded by #204 |
Resolves #102