task.Cancel

Heya, I was curious if I may suggest an idea on how to deal with the Cancel method here:

task<native><public>(t:type)<computes> := class<abstract><final>(awaitable(t)):
    #...
    Await<native><override>()<suspends>:t
    Cancel<native><epic_internal>():void

Based on some tests I conducted, it seems there are two core issues currently:

  • Self-cancellation:
    The task could try to cancel itself, which would not result in immediate cancellation because it would continue running until the next suspending call or its return. However, this does not seem to be a major issue since it does not cause any real problems. The user could simply use return if they want to avoid this behavior.

  • Return value of task.Await:
    The task.Await method must return a value. Therefore, invoking task.Cancel would either make task.Await wait indefinitely or return an invalid value. What if task.Await were to return ?t instead of t? This way, if something uses task.Await, it would return false if the task is being canceled; otherwise, it would return an option{ReturnValue}. I understand this would break backward compatibility for those who have previously used task.Await, but it seems to be a viable way to expose task.Cancel.

TL;DR:
When you make Await return an optional instead, you could expose the task.Cancel method.

Thank you for your feedback. While I cannot guarantee a response, I can confirm that this has been forwarded to the appropriate team.

1 Like