I Javascript snippet I wrote recently - I really couldn't be bother properly implementing the consumer (of this func) to be async - so I made the async func sync.
letdone=falseletresult=undefined;this.isAuthenticationValid().then((theResult)=>{done=true;result=theResult;})constasyncChecker=()=>{setTimeout(()=>{if(done===true){// i.e. promise has resolvedif(result===false){// i.e. not authenticatedthis.getStrategy().authenticate();}}else{// promise not yet resolved.asyncChecker();}},1000);}asyncChecker();
Appearances can be deceiving. On a technicality yes it's still async. However, from a callers perspective, it operates synchronously. The debate on if this is synchronous or non-synchronous was not the point of me posting this code. If you need a reminder, see the OP title.
I Javascript snippet I wrote recently - I really couldn't be bother properly implementing the consumer (of this func) to be async - so I made the async func sync.
N.B. this was in no way production code.
This is still async
Appearances can be deceiving. On a technicality yes it's still async. However, from a callers perspective, it operates synchronously. The debate on if this is synchronous or non-synchronous was not the point of me posting this code. If you need a reminder, see the OP title.
For the caller the function returns on the setTimeout call