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
Currently, xstate support catch error by subscribe, but if something store in context, or created by callback actor, once error raised, these resource can't be cleanup
image this.
describe('Callback actor with error threw',()=>{letcounter=1;letisOver=false;// a flag to detect clean or not.constmachine=setup({actors: {test: fromCallback(({ sendBack })=>{constaa=setInterval(()=>{counter++;sendBack({type: 'haha'+counter});},100);return()=>{clearInterval(aa);isOver=true;// mark we cleand it.};}),},}).createMachine({invoke: {src: 'test',},initial: 'idle',states: {idle: {on: {haha3: {actions: ()=>{thrownewError('haha');},},},},},});it('should works when throw error',async()=>{constactor=createActor(machine);actor.start();// setTimeout(() => {// actor.stop();// }, 300);try{awaittoPromise(actor);}catch(e){actor.stop();// this not work cause the machine status is error.// console.log(actor.getSnapshot());expect(e.message).toMatch('haha');// ✅ we not catch the Error we threw.}expect(counter).toBeGreaterThan(2);// ✅expect(isOver).toBeTruthy();// 🔴 this will failed , the cleanup function can't reach});});
So, can we provide a way to clean there resource in machine? like Promise's finally , then we can clean some resource whatever whenever whereever errors threw. so that we can coding happly without care about resource cleanup.
Description:
Currently, xstate support catch error by subscribe, but if something store in context, or created by callback actor, once error raised, these resource can't be cleanup
image this.
So, can we provide a way to clean there resource in machine? like Promise's
finally
, then we can clean some resource whatever whenever whereever errors threw. so that we can coding happly without care about resource cleanup.ref: https://discord.com/channels/795785288994652170/1203727111312121987
The text was updated successfully, but these errors were encountered: