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
To use `async`/`await`, you may find it more expressive to wrap your code in an [asynchronous immediately invoked function expression (IIFE)](https://developer.mozilla.org/en-US/docs/Glossary/IIFE#execute_an_async_function).
444
-
445
-
```ts
446
-
const machine =createMachine({
447
-
initial: 'running',
448
-
states: {
449
-
running: {
450
-
invoke: {
451
-
src: fromCallback(({ sendBack }) => {
452
-
// highlight-start
453
-
(async () => {
454
-
try {
455
-
const data =awaitsomePromise();
456
-
sendBack({ type: 'done', data });
457
-
} catch (error) {
458
-
sendBack({ type: 'error', data: error });
459
-
}
460
-
})();
461
-
// highlight-end
462
-
463
-
return () => {
464
-
/* cleanup function */
465
-
};
466
-
})
467
-
},
468
-
// highlight-start
469
-
on: {
470
-
error: {
471
-
actions: ({ event }) =>console.error(event.data)
472
-
}
473
-
}
474
-
// highlight-end
475
-
}
476
-
}
477
-
});
478
-
```
479
-
480
443
## Higher-level actor logic
481
444
482
445
Higher-level actor logic enhances existing actor logic with additional functionality. For example, you can create actor logic that logs or persists actor state:
0 commit comments