Git Product home page Git Product logo

Comments (7)

weekens avatar weekens commented on August 28, 2024

Custom actor parameters are not yet implemented in Comedy, but this feature should certainly be present.

There is, however, a resource injection mechanism in Comedy. It's not yet documented, but you can see examples in test/test-system.js ("should properly inject resources defined in contexts" and the like).

If shared resource is not what you need, you can try to get away with initialization message.

from comedy.

vallettea avatar vallettea commented on August 28, 2024

Yes but you have the same problem when you define your context:

class MyContext {
      initialize() {
        this.resource = myVariable;
      }

      getResource() {
        return this.resource;
      }
    }

myVariable is unknown

from comedy.

weekens avatar weekens commented on August 28, 2024

Yes, the context with all it's resources is supposed to be self-contained.

In your case, the initialization message would work. Custom actor parameters will be implemented shortly.

from comedy.

weekens avatar weekens commented on August 28, 2024

Implemented in v0.1.0. Here is an example test:

it('should be able to pass custom parameters to child actor', P.coroutine(function*() {
  class MyActor {
    initialize(selfActor) {
      this.helloResponse = selfActor.getCustomParameters().helloResponse;
    }

    hello() {
      return this.helloResponse;
    }
  }

  // Create child actor with custom parameter.
  var childActor = yield rootActor.createChild(MyActor, {
    mode: 'forked',
    customParameters: { helloResponse: 'Hi there!' }
  });

  var response = yield childActor.sendAndReceive('hello');

  expect(response).to.be.equal('Hi there!');
}));

Enjoy!

from comedy.

vallettea avatar vallettea commented on August 28, 2024

Works perfectly THANKS.

from comedy.

vallettea avatar vallettea commented on August 28, 2024

It seems that if I put a function in the parameters it works for non-forked actor but that functions are filtered out of the parameters when the actor is forked.
Any idea how to pass functions as parameters for forked actors ?

from comedy.

weekens avatar weekens commented on August 28, 2024

Well, yeah, for now I've just added support for plain objects in custom parameters. Class and function passing will be done in a next step (you can create an issue for that).

from comedy.

Related Issues (20)

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.