Code Monkey home page Code Monkey logo

typescript-multiparty-sessions's Issues

JSON gets parsed twice if browser endpoint receives messages in certain orders

global protocol Test(role S, role C, role A) {
    login(number) from C to A;
    pay(number) from C to S;
    blah() from C to A;
    acc(number) from S to C;
}

If S sends acc(number) before C sends blah(), then you get:

"C cancelled session: JSON.parse: unexpected character at line 1 column 2 of the JSON data"

This happens because of line 300 in codegen/generator/browser/templates/runtime.tsx.j2, which should use the data variable instead of the message variable, since message has been parsed already, but then the handle function in C's receive state tries to parse it again.

I am gonna try and make a PR for this.

Receiver component doesn't re-register for messages unless state changes

I fixed this during my thesis but totally forgot about it until now. Gonna try and remember how scribble works...

global protocol ReceiverBug(role A, role B) {
  rec Loop {
    choice at A {
      msg1() from A to B;
      continue Loop;
    } or {
      msg2() from A to B;
      continue Loop;
    }
  }
}

the handler registration of B is tied to componentDidMount, but if the state didn't change โ€” since there's just one state for B here โ€” then that method won't get called because the receiver component never has to mount again. Without checking for this, B stops being able to receive messages after the first message

associated PR: #52

Add factory function for successor states in generated API

const logic = new Implementation.Initial({
  [Labels.S17.Destination]: async (dest) => {
    const result = await checkAvailable(dest);
    if (result.available) {
      return new Implementation.S19([
        Labels.S19.Available, [result.price], ...
      ]);
    } else {
      return new Implementation.S19([
        Labels.S19.Full, [], logic
      ]);
    }
  }
});

It should be possible to change the type definition for the async function to take one more argument before dest that offers two functions: available() and full(). These take the next logic followed by the required messages (using the vararg pattern). With that, IDE users will get better guidance towards the correct implementation. For example, if I started my function like async (nextStep, dest) => then I could write nextStep. and would get automatic completions for the choices I have.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.