@@ -137,24 +137,30 @@ worker_destroy(_WorkerRef) ->
137137
138138% % @doc Call a Python function from a worker.
139139% % This is a dirty NIF that acquires the GIL.
140+ % % May return {suspended, ...} if Python calls erlang.call() (reentrant callback).
140141-spec worker_call (reference (), binary (), binary (), list (), map ()) ->
141- {ok , term ()} | {error , term ()}.
142+ {ok , term ()} | {error , term ()} | { suspended , term (), reference (), { binary (), term ()}} .
142143worker_call (_WorkerRef , _Module , _Func , _Args , _Kwargs ) ->
143144 ? NIF_STUB .
144145
145146% % @doc Call a Python function from a worker with timeout.
147+ % % May return {suspended, ...} if Python calls erlang.call() (reentrant callback).
146148-spec worker_call (reference (), binary (), binary (), list (), map (), non_neg_integer ()) ->
147- {ok , term ()} | {error , term ()}.
149+ {ok , term ()} | {error , term ()} | { suspended , term (), reference (), { binary (), term ()}} .
148150worker_call (_WorkerRef , _Module , _Func , _Args , _Kwargs , _TimeoutMs ) ->
149151 ? NIF_STUB .
150152
151153% % @doc Evaluate a Python expression in a worker.
152- -spec worker_eval (reference (), binary (), map ()) -> {ok , term ()} | {error , term ()}.
154+ % % May return {suspended, ...} if Python calls erlang.call() (reentrant callback).
155+ -spec worker_eval (reference (), binary (), map ()) ->
156+ {ok , term ()} | {error , term ()} | {suspended , term (), reference (), {binary (), term ()}}.
153157worker_eval (_WorkerRef , _Code , _Locals ) ->
154158 ? NIF_STUB .
155159
156160% % @doc Evaluate a Python expression in a worker with timeout.
157- -spec worker_eval (reference (), binary (), map (), non_neg_integer ()) -> {ok , term ()} | {error , term ()}.
161+ % % May return {suspended, ...} if Python calls erlang.call() (reentrant callback).
162+ -spec worker_eval (reference (), binary (), map (), non_neg_integer ()) ->
163+ {ok , term ()} | {error , term ()} | {suspended , term (), reference (), {binary (), term ()}}.
158164worker_eval (_WorkerRef , _Code , _Locals , _TimeoutMs ) ->
159165 ? NIF_STUB .
160166
@@ -255,8 +261,9 @@ send_callback_response(_Fd, _Response) ->
255261% % @doc Resume a suspended Python callback with the result.
256262% % StateRef is the reference returned in the {suspended, ...} tuple.
257263% % Result is the callback result as a binary (status byte + data).
258- % % Returns {ok, FinalResult} or {error, Reason}.
259- -spec resume_callback (reference (), binary ()) -> {ok , term ()} | {error , term ()}.
264+ % % Returns {ok, FinalResult}, {error, Reason}, or another {suspended, ...} for nested callbacks.
265+ -spec resume_callback (reference (), binary ()) ->
266+ {ok , term ()} | {error , term ()} | {suspended , term (), reference (), {binary (), term ()}}.
260267resume_callback (_StateRef , _Result ) ->
261268 ? NIF_STUB .
262269
0 commit comments