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

Choreographies can currently only accept Located messages as arguments #31

Open
ImpregnableProgrammer opened this issue Aug 15, 2023 · 0 comments

Comments

@ImpregnableProgrammer
Copy link
Contributor

ImpregnableProgrammer commented Aug 15, 2023

At the moment, the choreographies can only accept unicast messages of type Located as arguments. This seems problematic for the colocally operator since then the inner choreography for colocally cannot be passed messages of type Colocated, which doesn't make sense since colocally works with multiple locations at once, so it makes more sense for it to be able to accept Colocated messages sent to multiple locations. Choreographies also cannot return messages of type Colocated at the moment, which again seems problematic for the colocally operator.

For example, the following is currently considered invalid:

type Locations = "alice" | "bob" | "carol" | "dave";

const dualResponse: Choreography<
  Locations,
  [Colocated<string, "alice" | "bob" | "dave">, Colocated<string, "carol" | "bob" | "dave">],
  [Colocated<string, "bob" | "alice" | "carol">, Colocated<string, "dave" | "alice" | "carol">]
> = async ({ locally, peel, multicast }, [msgAlice, msgCarol]) => {
  const aliceMsg = peel(msgAlice as Colocated<string, Locations>);
  const carolMsg = peel(msgCarol as Colocated<string, Locations>);
  if (aliceMsg.length > 0 && carolMsg.length > 0) {
    const responseBob = await locally("bob", () => "hi, this is bob");
    const colocatedBob = await multicast(
      "bob",
      ["alice", "carol"],
      responseBob
    );
    const responseDave = await locally("dave", () => "hi, this is dave");
    const colocatedDave = await multicast(
      "dave",
      ["alice", "carol"],
      responseDave
    );
    return [colocatedBob, colocatedDave];
  }
  return ["", ""];
};

const test: Choreography<
  Locations,
  [],
  [Colocated<string, "bob" | "alice" | "carol">, Colocated<string, "dave" | "alice" | "carol">]
> = async ({ locally, multicast, colocally }) => {
  const msgAtAlice = await locally("alice", () => "hi from alice");
  const colocatedAlice = await multicast(
    "alice",
    ["bob", "dave"],
    msgAtAlice
  );
  const msgAtCarol = await locally("carol", () => "hi from carol");
  const colocatedCarol = await multicast(
    "carol",
    ["bob", "dave"],
    msgAtCarol
  );
  const responses = await colocally(["bob", "dave"], dualResponse, [
    colocatedAlice,
    colocatedCarol,
  ]);
  return responses;
};

Here, we have the dualResponse choreography accepting two Colocated messages as arguments when it's used with colocally in the test choreography. We also have dualResponse returning two Colocated messages in response. It seems like this should be valid, which is why I'm proposing to amend the Choreography type to allow for choreographies that can accept and return both the Located and Colocated message types. Making this change would also mean that the no-unused-colocated-location ESLint rule would need to be amended to handle this situation.

@ImpregnableProgrammer ImpregnableProgrammer changed the title Choreographies currently only accept Located messages as arguments Choreographies can currently only accept Located messages as arguments Aug 15, 2023
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

1 participant