Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stateless Actors won't handle errors #142

Open
juanstiza opened this issue Jul 6, 2023 · 1 comment
Open

Stateless Actors won't handle errors #142

juanstiza opened this issue Jul 6, 2023 · 1 comment

Comments

@juanstiza
Copy link

Stateless actors are unable to catch errors being thrown in the main function.
I assume this should be the case, but please let me know if it is not. I will fall-back to using regular actors.

Expected Behavior

An error being thrown inside a Stateless actor's function should:

  1. Be caught
  2. Be handled by onCrash and escalated properly

Current Behavior

Error doesn't get thrown and actor get's stuck

Possible Solution

No clue

Steps to Reproduce (for bugs)

import nact from "nact";
const system = nact.start();
const delay = (time) => new Promise((res) => setTimeout(res, time));

const ping = nact.spawnStateless(
  system,
  async (msg, ctx) => {
    console.log(msg);
    await delay(500);

    throw new Error("oh no!");
  },
  "ping",
  {
    onCrash: (msg, e, ctx) => {
      console.log(e)
      return ctx.escalate
    }
  }
);

nact.dispatch(ping, {
  hello: "World!"
});

This outputs:

{ hello: 'World!' }

Context

I'm trying to use stateless actors to perform simple tasks, but I need these to respond to errors

Your Environment

Tested in node v14.21.3 and v18.14.2 on MacOS 13.4.1

@ncthbrt
Copy link
Collaborator

ncthbrt commented Jul 10, 2023

@juanstiza I'd recommend that you take a look at https://www.npmjs.com/package/@nact/core, as this should I believe fix this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants