diff --git a/lib/actor.js b/lib/actor.js index 087f8dd..7c9be3f 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -76,7 +76,7 @@ class Actor extends EventEmitter { createChild(definition, config) { if (this.getState() != 'new' && this.getState() != 'ready') return this._notReadyErrorPromise(); - + let log = this.getLog(); let childPromise = this.system.createActor(definition, this._parentReference(), config) .tap(actor => actor.initialize()) @@ -127,7 +127,7 @@ class Actor extends EventEmitter { let newActor = await this.system._createActor( this.origDefinition || this.definition, this.parent, - _.extend({ name: this.getName() }, config)); + _.extend({ name: this.getName(), customParameters: this.getCustomParameters() }, config)); await newActor.initialize(); await this.parent._augmentChild(this.getId(), newActor); @@ -318,7 +318,7 @@ class Actor extends EventEmitter { return this._overloadedErrorPromise(); let fwActor = this._checkForward(topic); - + if (fwActor) { if (this.getLog().isDebug()) { this.getLog().debug('Forwarding message to other actor, topic=', topic, @@ -436,7 +436,7 @@ class Actor extends EventEmitter { this._setState('destroying'); this.log.debug('Destroying...'); - + this.destroyPromise = P .map(this.childPromises, child => { return child.destroy() @@ -684,4 +684,4 @@ class Actor extends EventEmitter { } } -module.exports = Actor; \ No newline at end of file +module.exports = Actor; diff --git a/test/typescript/test-hot-config-change.ts b/test/typescript/test-hot-config-change.ts index cb4ae71..9169ca9 100644 --- a/test/typescript/test-hot-config-change.ts +++ b/test/typescript/test-hot-config-change.ts @@ -9,7 +9,7 @@ import * as actors from '../../'; import {expect} from 'chai'; -import {Actor, ActorRef, ActorSystem} from '../../index'; +import { Actor, ActorDefinition, ActorRef, ActorSystem } from '../../index'; import {afterEach, beforeEach} from 'mocha'; import * as common from '../../lib/utils/common'; import _ = require('underscore'); @@ -194,6 +194,42 @@ describe('Hot configuration change', () => { expect(finalPid).to.be.not.equal(pid2); expect(finalPid).to.be.not.equal(pid3); }); + + it('should respect custom parameters', async () => { + class TestActor implements ActorDefinition { + private selfActor: Actor; + + initialize(selfActor: Actor): void { + this.selfActor = selfActor; + } + + test() { + return `${this.selfActor.getCustomParameters().greeting} ${process.pid}`; + } + + destroy(): void { + // Nothing to do. + } + } + + let testActor = await rootActor.createChild(TestActor, { + mode: 'in-memory', + customParameters: { + greeting: 'Hello!' + } + }); + + let message = await testActor.sendAndReceive('test'); + + expect(message).to.match(/Hello! \d+/); + + await testActor.changeConfiguration({ mode: 'forked' }); + + let forkedMessage = await testActor.sendAndReceive('test'); + + expect(forkedMessage).to.match(/Hello! \d+/); + expect(forkedMessage).to.be.not.equal(message); + }); }); describe('changeGlobalConfiguration()', () => {