Replies: 2 comments 2 replies
-
|
Interim solution that isn't so unspeakably bad: have the actors brand the /**
* resourceActor({
* acquire: async (options) => {...},
* release: async (resource) => {...},
* })
*/
function resourceActor({ acquire, release }) {
return fromCallback(({ input: options, self, sendBack }) => {
var resource_ = Promise.resolve(acquire(options));
resource_.then(
(result) => void sendBack({ type: "ready", output: result, _fixme_xstate_5335: self.id }),
(error) => void sendBack({ type: "error", error })
);
return () => void resource_.then((result) => release(result));
});
}
/**
* on: {
* ready: {
* guard: fromActor("some_invoked_actor"),
* actions: assign({ some_resource: ({ event }) => event.output }),
* target: "ready",
* },
* },
*/
function fromActor(id) {
return ({ event }) => (event._fixme_xstate_5335 === id);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Would using |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to wait for several resources to be acquired before advancing my state machine from
recording.acquiringtorecording.recording.I thought that I should do this by making
recording.acquiringa parallel state, for each resource that needs to be acquired, using itsonDoneevent to assign the result & then mark its parallel childready(final); then using therecording.acquiringonDonetransition to enterrecording.recording.This nearly worked, except that when the invoked actor
onDonehandlers try to switch the parallel child state, they end up resetting the state of all that parallel child's peers. (I thought to use invoked actors so that I can guarantee resources are cleaned up when the masterrecordingstate is eventually exited, no matter what reason.)Setting
reenter: falsedid not fix this. How can I accomplish what I'm trying to accomplish?OK, on further study, I realized that a Promise actor isn't quite the correct tool here.
But when using other actors, which don't "produce output" and have to be wired up with a custom
readyevent, I'm having a hard time finding any clean way to discriminate the different actors'readyevents from one another:Beta Was this translation helpful? Give feedback.
All reactions