id: 'myStateMachine',
initial: 'initiate',
context: {
results: undefined,
errorMessage: undefined
},
states: {
initiate: {
on : {
startProcessing : 'fetchGenericDetails',
cancelRequest : 'cancelled'
}
},
fetchGenericDetails: {
type: 'parallel',
states: {
firstAsyncRequest: {
invoke: {
id: 'firstAsyncRequest',
src : (context) => getFirstAsyncRequest(context),
}
},
secondAsyncRequest: {
invoke: {
id: 'secondAsyncRequest',
src : (context) => getSecondAsyncRequest(context),
}
},
thirdAsyncRequest: {
invoke: {
id: 'thirdAsyncRequest',
src : (context) => getThirdAsyncRequest(context),
}
},
},
onDone: "success"
},
success: {
entry : 'success'
},
cancelled: {
entry: 'sendCancellationNotification',
},
}
},{
actions : {
success : async (context) => {
console.log('post :: success ===>>>',context);
},
sendCancellationNotification: () => {
// Send a notification for order cancellation
console.log('updating sendCancellationNotification ::>')
},
}
});```