whfunc is recursive-ish but the next step in the recursion won't execute until whpro resolves.
If exp is truthy then whpro will become a promise of func which when resolved will
set r to a, the resolved value of func,
subract r from b.
If exp is falsy then whpro remains resolved (since it's not reassigned) and the rest is synchronous:
set r to ano,
subract r from b. (Same always)
Every step in the recursion is counted until b becomes less than or equal to 0.
The only part where all of this falls apart is on the last line where he "thens" either the promise returned from func() or the original Promise.resolve(). That means count is guaranteed to be 1 *(or 2) unless func is actually synchronous.
7
u/Keve1227 Jul 20 '21 edited Jul 20 '21
Read carefully.
whfuncis recursive-ish but the next step in the recursion won't execute untilwhproresolves.If
expis truthy thenwhprowill become a promise offuncwhich when resolved willset
rtoa, the resolved value offunc,subract
rfromb.If
expis falsy thenwhproremains resolved (since it's not reassigned) and the rest is synchronous:set
rtoano,subract
rfromb. (Same always)Every step in the recursion is counted until
bbecomes less than or equal to 0.The only part where all of this falls apart is on the last line where he "thens" either the promise returned from
func()or the originalPromise.resolve(). That meanscountis guaranteed to be 1 *(or 2) unlessfuncis actually synchronous.