@@ -681,16 +681,16 @@ async calls (until some active calls finish):
681
681
``` python
682
682
class AsyncTask (Task ):
683
683
ft: FuncType
684
- start_thunk : Callable
685
- return_thunk : Callable
684
+ on_start : Callable
685
+ on_return : Callable
686
686
state: AsyncCallState
687
687
unblock_next_pending: bool
688
688
689
- def __init__ (self , opts , inst , caller , ft , start_thunk , return_thunk ):
689
+ def __init__ (self , opts , inst , caller , ft , on_start , on_return ):
690
690
super ().__init__ (opts, inst, caller)
691
691
self .ft = ft
692
- self .start_thunk = start_thunk
693
- self .return_thunk = return_thunk
692
+ self .on_start = on_start
693
+ self .on_return = on_return
694
694
self .state = AsyncCallState.STARTING
695
695
self .unblock_next_pending = False
696
696
@@ -1925,12 +1925,12 @@ When instantiating component instance `$inst`:
1925
1925
The resulting function ` $f ` takes 3 runtime arguments:
1926
1926
* ` caller ` : the caller's ` Task ` or, if this lifted function is being called by
1927
1927
the host, ` None `
1928
- * ` start_thunk ` : a nullary function that must be called to return the caller's
1928
+ * ` on_start ` : a nullary function that must be called to return the caller's
1929
1929
arguments as a list of component-level values
1930
- * ` return_thunk ` : a unary function that must be called after ` start_thunk ` ,
1930
+ * ` on_return ` : a unary function that must be called after ` on_start ` ,
1931
1931
passing the list of component-level return values
1932
1932
1933
- The indirection of ` start_thunk ` and ` return_thunk ` are used to model the
1933
+ The indirection of ` on_start ` and ` on_return ` are used to model the
1934
1934
interleaving of reading arguments out of the caller's stack and memory and
1935
1935
writing results back into the caller's stack and memory, which will vary in
1936
1936
async calls.
@@ -1949,21 +1949,21 @@ by a *single host-agnostic component*.
1949
1949
1950
1950
Based on this, ` canon_lift ` is defined:
1951
1951
``` python
1952
- async def canon_lift (opts , inst , callee , ft , caller , start_thunk , return_thunk ):
1952
+ async def canon_lift (opts , inst , callee , ft , caller , on_start , on_return ):
1953
1953
if opts.sync:
1954
1954
task = SyncTask(opts, inst, caller)
1955
1955
await task.enter()
1956
1956
1957
- flat_args = lower_sync_values(task, MAX_FLAT_PARAMS , start_thunk (), ft.param_types())
1957
+ flat_args = lower_sync_values(task, MAX_FLAT_PARAMS , on_start (), ft.param_types())
1958
1958
flat_results = await call_and_trap_on_throw(callee, task, flat_args)
1959
- return_thunk (lift_sync_values(task, MAX_FLAT_RESULTS , CoreValueIter(flat_results), ft.result_types()))
1959
+ on_return (lift_sync_values(task, MAX_FLAT_RESULTS , CoreValueIter(flat_results), ft.result_types()))
1960
1960
1961
1961
if opts.post_return is not None :
1962
1962
[] = await call_and_trap_on_throw(opts.post_return, task, flat_results)
1963
1963
1964
1964
task.exit()
1965
1965
else :
1966
- task = AsyncTask(opts, inst, caller, ft, start_thunk, return_thunk )
1966
+ task = AsyncTask(opts, inst, caller, ft, on_start, on_return )
1967
1967
await task.enter()
1968
1968
1969
1969
if not opts.callback:
@@ -1991,8 +1991,8 @@ async def call_and_trap_on_throw(callee, task, args):
1991
1991
```
1992
1992
The only fundamental difference between sync and async lifting is whether
1993
1993
parameters/results are automatically lowered/lifted (with ` canon_lift ` calling
1994
- ` start_thunk ` and ` return_thunk ` ) or whether the ` callee ` explicitly triggers
1995
- ` start_thunk ` /` return_thunk ` via ` task.start ` /` task.return ` (defined below).
1994
+ ` on_start ` and ` on_return ` ) or whether the ` callee ` explicitly triggers
1995
+ ` on_start ` /` on_return ` via ` task.start ` /` task.return ` (defined below).
1996
1996
The latter gives the callee the ability to explicitly apply backpressure (by
1997
1997
waiting before calling ` task.start ` ) whereas the former applies "backpressure"
1998
1998
immediately if a sync call is already running. In both cases, backpressure is
@@ -2050,29 +2050,29 @@ async def canon_lower(opts, callee, ft, task, flat_args):
2050
2050
if opts.sync:
2051
2051
subtask = Subtask(opts, task.inst)
2052
2052
2053
- def start_thunk ():
2053
+ def on_start ():
2054
2054
return lift_sync_values(subtask, MAX_FLAT_PARAMS , flat_args, ft.param_types())
2055
2055
2056
- def return_thunk (results ):
2056
+ def on_return (results ):
2057
2057
nonlocal flat_results
2058
2058
flat_results = lower_sync_values(subtask, MAX_FLAT_RESULTS , results, ft.result_types(), flat_args)
2059
2059
2060
- await callee(task, start_thunk, return_thunk )
2060
+ await callee(task, on_start, on_return )
2061
2061
2062
2062
subtask.finish()
2063
2063
else :
2064
2064
subtask = AsyncSubtask(opts, task.inst)
2065
2065
2066
2066
async def do_call ():
2067
- def start_thunk ():
2067
+ def on_start ():
2068
2068
subtask.start()
2069
2069
return lift_async_values(subtask, flat_args, ft.param_types())
2070
2070
2071
- def return_thunk (results ):
2071
+ def on_return (results ):
2072
2072
subtask.return_()
2073
2073
lower_async_values(subtask, results, ft.result_types(), flat_args)
2074
2074
2075
- await callee(task, start_thunk, return_thunk )
2075
+ await callee(task, on_start, on_return )
2076
2076
subtask.finish()
2077
2077
2078
2078
asyncio.get_event_loop().set_task_factory(asyncio.eager_task_factory)
@@ -2091,7 +2091,7 @@ async def canon_lower(opts, callee, ft, task, flat_args):
2091
2091
In the async case, the combination of ` asyncio.create_task ` with
2092
2092
` eager_task_factory ` immediately start executing ` do_call ` without ` await ` ing
2093
2093
it. Following ` create_task ` , ` do_call ` has either completed eagerly (with
2094
- ` return_thunk ` having been called to write the return values into the
2094
+ ` on_return ` having been called to write the return values into the
2095
2095
caller-supplied memory buffer), in which case the lowered function can simply
2096
2096
return ` 0 ` to indicate "done". Otherwise, the coroutine is still running, in
2097
2097
which case it is added to an instance-wide table of active async subtasks,
@@ -2246,7 +2246,7 @@ async def canon_task_start(task, core_ft, flat_args):
2246
2246
trap_if(task.opts.sync)
2247
2247
trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType([], task.ft.params), ' lower' ))
2248
2248
task.start()
2249
- args = task.start_thunk ()
2249
+ args = task.on_start ()
2250
2250
flat_results = lower_sync_values(task, MAX_FLAT_RESULTS , args, task.ft.param_types(), CoreValueIter(flat_args))
2251
2251
assert (len (core_ft.results) == len (flat_results))
2252
2252
return flat_results
@@ -2277,7 +2277,7 @@ async def canon_task_return(task, core_ft, flat_args):
2277
2277
trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType(task.ft.results, []), ' lower' ))
2278
2278
task.return_()
2279
2279
results = lift_sync_values(task, MAX_FLAT_PARAMS , CoreValueIter(flat_args), task.ft.result_types())
2280
- task.return_thunk (results)
2280
+ task.on_return (results)
2281
2281
assert (len (core_ft.results) == 0 )
2282
2282
return []
2283
2283
```
0 commit comments