You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the function should wrap a function as async version of it
if it is called the first time, it should be able to remember the result and return this result, without calling the action again
it should also be able to reset its state
importassertfrom"assert"const{ setTimeout }=require('timers/promises')import{withMemory}from"@marcelkloubert/promises"constmyAsyncFunc=async(value: number)=>{return{time: newDate(),value2x: value*2}}constmyWrappedAction=withMemory(myAsyncFunc)// new, because not invoked with these argument yetconstresult1a=awaitmyWrappedAction(1)awaitsetTimeout(1000)// cachedconstresult1b=awaitmyWrappedAction(1)// also new, because not invoked with these argument yetconstresult2a=awaitmyWrappedAction(2)awaitsetTimeout(1000)// cachedconstresult2b=awaitmyWrappedAction(2)// wrapped function whould have this method// to reset all statesmyWrappedAction.reset()// now all actions are invoked againconstresult1c=awaitmyWrappedAction(1)constresult2c=awaitmyWrappedAction(2)// reset one cached statemyWrappedAction.resetOne(2)// cachedconstresult1d=awaitmyWrappedAction(1)// not cachedconstresult2d=awaitmyWrappedAction(2)
The text was updated successfully, but these errors were encountered:
the function should wrap a function as async version of it
if it is called the first time, it should be able to remember the result and return this result, without calling the action again
it should also be able to reset its state
The text was updated successfully, but these errors were encountered: