-
Notifications
You must be signed in to change notification settings - Fork 36
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
Actor initialization with parameters #5
Comments
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 If shared resource is not what you need, you can try to get away with initialization message. |
Yes but you have the same problem when you define your context:
|
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. |
Implemented in 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! |
Works perfectly THANKS. |
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. |
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). |
[I've been working a couple of days with your library and I wanted to thanks you because I really enjoy it.]
Coming back to my question, how can I initialize an actor with some parameters ?
When an actor is forked, it doesn't have access to the scope.
The text was updated successfully, but these errors were encountered: