Cancelling a Process.sleep task before it fulfills

Hi! :wave:

I want to cancel a Process.sleep task I spawned before it resolves and sends a message back to the update function.

I asked googled a lot, tried my own code, and asked in slack, and couldn’t find a way to do it with Tasks and Process.

Is this possible?

Code:

  • First try: https://ellie-app.com/5zqtzfQMRZxa1
    • Failure, since that seems to perform two different tasks even if they are the same instance, so when cancelling it only cancels the spawned one but it still times out
  • Another try, by @szubtsovskiy: https://ellie-app.com/5zqF55LKc92a1
    • Fail as well, as it cancels properly, but the timeout never triggers the message back to the update function (I guess it happens in the process separately, not doing anything useful)

So finally: Is there a way to cancel a timer? It is fine if the answer is no!

Please focus on the question and code, thank you. I think I do know how to ignore message results in update by attaching unique ids to the timeouts for example, as well as other techniques. That is not what this question is about. Thank you!

4 Likes

I’m guessing from the lack of comments that there is no way to cancel sleep tasks right now.

Do Process.spawn and kill have any utility in applications? If anyone has some public code with examples to understand when they are useful it would be much appreciated.

It looks like it isn’t possible right now, the timeout id is only kept in closure in _Process_sleep and isn’t available for Process.kill, calling Process.spawn gives you a new process ID, so it will always be one above what you would need to call clearTimeout(Id), the only way now seems to be ignoring the message in your update.

Thanks for digging in @antew.

If anyone has some examples of good use cases for the process module they would be very much appreciated:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.