It isn't a recursive function as it isn't calling itself (or being called via mutual recursion); the syntax sugar only makes it look that way.
Roughly:
functionstuff(){returnnewPromise<void>(executor);// ---functionexecutor(resolve:()=>void,_reject:(reason?:Error)=>void):void{// `someAsyncOperation()` is on the callstack// but `finish()` is only placed on the// microtask queue once// `someAsyncOperation()` resolves// When `finish()` starts the // callstack is (practically) empty//someAsyncOperation().then(finish);// ---functionfinish(){stuff();resolve();}}}
By the time you hit the .then() in executor()stuff() is done. The finish() portion is scheduled in a microtask, not called.
You could however argue that stuff() is recursively scheduled.
It isn't a recursive function as it isn't calling itself (or being called via mutual recursion); the syntax sugar only makes it look that way.
Roughly:
By the time you hit the
.then()
inexecutor()
stuff()
is done. Thefinish()
portion is scheduled in a microtask, not called.You could however argue that
stuff()
is recursively scheduled.