forgottenserver icon indicating copy to clipboard operation
forgottenserver copied to clipboard

addTask(callback, ...) lua function

Open yamaken93 opened this issue 4 years ago • 16 comments

Pull Request Prelude

Changes Proposed

implements addTask lua c function so we can access the engine g_dispatcher.addTask function like addEvent and g_scheduler.addEvent.

yamaken93 avatar Sep 28 '21 14:09 yamaken93

Can you describe an example scenario where having this functionality would be useful?

Erza avatar Sep 28 '21 21:09 Erza

Can you describe an example scenario where having this functionality would be useful?

If you want the function(task) to be executed in the next frame(dispatcher cycle) asap without any delay.

yamaken93 avatar Sep 28 '21 22:09 yamaken93

Can you describe an example scenario where having this functionality would be useful?

If you want the function(task) to be executed in the next frame(dispatcher cycle) asap without any delay.

Sure, but in which example scenario would you want to do that?

Erza avatar Sep 28 '21 22:09 Erza

addEvent with 1ms is not the same?

Kamenuvol avatar Sep 29 '21 03:09 Kamenuvol

the dispatcher executes tasks in another thread is it correct?

MillhioreBT avatar Sep 29 '21 07:09 MillhioreBT

the dispatcher executes tasks in another thread is it correct?

Yes, dispatcher and scheduler are using their own threads, but tasks are only executed in dispatcher thread.

nekiro avatar Sep 29 '21 10:09 nekiro

I think i may drop this pr and then change addEvent to use g_dispatcher.addTask when the delay is 0.

yamaken93 avatar Oct 04 '21 16:10 yamaken93

I think i may drop this pr and then change addEvent to use g_dispatcher.addTask when the delay is 0.

Seems like a much better idea to me

Erza avatar Oct 07 '21 00:10 Erza

So we should add addTask or internally when someone call addEvent with 0 interval parameter it should add the task to dispatcher?

yamaken93 avatar Feb 06 '22 23:02 yamaken93

I'd say the latter.

DSpeichert avatar Feb 06 '22 23:02 DSpeichert

I still think we should add this addTask function. Why? Its problematic to change this ancient addEvent function parameters, since its has been a given for ages the minimum delay is 100 ms and its also problematic to under the hood make addEvent to add the task to dispatcher instead of scheduler because for the API sake the user script should be able to call addEvent and in the next line call stopEvent and its not possible or easier to implement that cancellable tasks in dispatcher + hacks in addEvent to support tihs. So the only two options for me are: add this addTask function or remove the 100 ms minimum delay from addEvent which will work basically as adding the task to the dispatcher when delay is 0 but will keep the stopEvent function working.

yamaken93 avatar Feb 10 '22 22:02 yamaken93

Remove the minimum delay?

Wasn't there a reason this was implemented though?

DSpeichert avatar Feb 14 '22 00:02 DSpeichert

Remove the minimum delay?

Wasn't there a reason this was implemented though?

Probably a protection for performance reasons.

yamaken93 avatar Feb 14 '22 00:02 yamaken93

@nekiro @DanielChabrowski @MillhioreBT @ranisalt I'm willing to finally finish this. We should decide, add this api or remove the minimum delay from addEvent or add something like addEventEx whithout the minimum delay.

yamaken93 avatar Sep 21 '22 18:09 yamaken93

@nekiro @DanielChabrowski @MillhioreBT @ranisalt I'm willing to finally finish this. We should decide, add this api or remove the minimum delay from addEvent or add something like addEventEx whithout the minimum delay.

I like addTask and am using it in some of my scripts. If addEventEx works all the same, I have no complaints about it, I'll take it.

MillhioreBT avatar Sep 21 '22 18:09 MillhioreBT

@nekiro @DanielChabrowski @MillhioreBT @ranisalt I'm willing to finally finish this. We should decide, add this api or remove the minimum delay from addEvent or add something like addEventEx whithout the minimum delay.

I like addTask and am using it in some of my scripts. If addEventEx works all the same, I have no complaints about it, I'll take it.

addEventEx would accept below 100 ms delay as parameter so it can work like addTask (with more overhead thanks to the timer system) if the delay is 0 and you will be able to cancel it if you call stopEvent before the task is added to the dispatcher.

yamaken93 avatar Sep 21 '22 18:09 yamaken93