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:
Thetask.Await
method must return a value. Therefore, invokingtask.Cancel
would either maketask.Await
wait indefinitely or return an invalid value. What iftask.Await
were to return?t
instead oft
? This way, if something usestask.Await
, it would returnfalse
if the task is being canceled; otherwise, it would return anoption{ReturnValue}
. I understand this would break backward compatibility for those who have previously usedtask.Await
, but it seems to be a viable way to exposetask.Cancel
.
TL;DR:
When you make Await return an optional instead, you could expose the task.Cancel
method.