CabalDAO
CabalDAO7mo ago

How can I run an internalAction from an

How can I run an internalAction from an internalMutation? It's telling me ctx.runAction from an internalMutation is not a function
3 Replies
Hmza
Hmza7mo ago
you cannot because actions are sync and mutations are async. you can run mutation from an action though. sorry. actions can perform asynchronous operations, including running mutations, but they do not have the same automatic retry behavior as mutations. so its better to use actions to run mutations if you have that requirement. @ballingt saw you typing. correct me if i'm wrong! thanks a - lot.
ballingt
ballingt7mo ago
This gets it across! Generally to run an internalAction from an internalMutation you'd schedule it with ctx.scheduler.runAfter(0, internal.foo.myAction, {}). At the JavaScript/TypeScript level I'd say both actions and mutations are async (they're functions that can return promises, and you can use await inside of them) but it's true that actions can run for much longer than mutations. Actions have a limit of something like 10 minutes, while mutations need to finish in a few seconds (it's helpful to make transactions short, and mutations are transactions). So running an action from a mutation would be a problem for these time limits.
CabalDAO
CabalDAOOP7mo ago
super helpful thank you very much

Did you find this page helpful?