@@ -2111,6 +2111,7 @@ containing the given resource representation in the current component
21112111instance's handle table:
21122112``` python
21132113async def canon_resource_new (rt , task , rep ):
2114+ trap_if(not task.inst.may_leave)
21142115 h = HandleElem(rep, own = True )
21152116 i = task.inst.handles.add(rt, h)
21162117 return [i]
@@ -2131,6 +2132,7 @@ current component instance's handle table and, if the handle was owning, calls
21312132the resource's destructor.
21322133``` python
21332134async def canon_resource_drop (rt , sync , task , i ):
2135+ trap_if(not task.inst.may_leave)
21342136 inst = task.inst
21352137 h = inst.handles.remove(rt, i)
21362138 flat_results = [] if sync else [0 ]
@@ -2223,6 +2225,7 @@ caller and lowers them into the current instance:
22232225``` python
22242226async def canon_task_start (task , core_ft , flat_args ):
22252227 assert (len (core_ft.params) == len (flat_args))
2228+ trap_if(not task.inst.may_leave)
22262229 trap_if(task.opts.sync)
22272230 trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType([], task.ft.params), ' lower' ))
22282231 task.start()
@@ -2253,6 +2256,7 @@ current instance and passes them to the caller:
22532256``` python
22542257async def canon_task_return (task , core_ft , flat_args ):
22552258 assert (len (core_ft.params) == len (flat_args))
2259+ trap_if(not task.inst.may_leave)
22562260 trap_if(task.opts.sync)
22572261 trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType(task.ft.results, []), ' lower' ))
22582262 task.return_()
@@ -2283,6 +2287,7 @@ returning the event (which is currently simply an `AsyncCallState` value)
22832287and writing the subtask index as an outparam:
22842288``` python
22852289async def canon_task_wait (task , ptr ):
2290+ trap_if(not task.inst.may_leave)
22862291 trap_if(task.opts.callback is not None )
22872292 event, payload = await task.wait()
22882293 store(task, payload, U32(), ptr)
@@ -2312,6 +2317,7 @@ available, returning whether or not there was such an event as a boolean and,
23122317if there was an event, storing the ` i32 ` event+payload pair as an outparam.
23132318``` python
23142319async def canon_task_poll (task , ptr ):
2320+ trap_if(not task.inst.may_leave)
23152321 ret = task.poll()
23162322 if ret is None :
23172323 return [0 ]
@@ -2333,6 +2339,7 @@ Calling `$f` calls `Task.yield_`, trapping if called when there is a `callback`.
23332339(When there is a callback, yielding is achieved by returning with the LSB set.)
23342340``` python
23352341async def canon_task_yield (task ):
2342+ trap_if(not task.inst.may_leave)
23362343 trap_if(task.opts.callback is not None )
23372344 await task.yield_()
23382345 return []
@@ -2353,6 +2360,7 @@ on `enqueued` ensures that supertasks can only drop subtasks once they've been
23532360officially notified of their completion (via ` task.wait ` or callback).
23542361``` python
23552362async def canon_subtask_drop (task , i ):
2363+ trap_if(not task.inst.may_leave)
23562364 subtask = task.inst.async_subtasks.remove(i)
23572365 trap_if(subtask.enqueued)
23582366 trap_if(subtask.state != AsyncCallState.DONE )
0 commit comments