Skip to content

Commit

Permalink
fix(AdapterConsumer): concurrently call behavior of ensureConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
CheerlessCloud committed Oct 12, 2018
1 parent 473b7f6 commit 937f70c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/AdapterConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class AdapterConsumer {
_adapter: ?_AMQPAdapter;
_connectParams: _ConnectOptions;
_errorHandler: Error => mixed = err => console.error(err);
_connectPromise: ?Promise<AMQPAdapter> = null;

_getAdapter(): AMQPAdapter {
if (!this._adapter) {
Expand All @@ -35,11 +36,18 @@ export default class AdapterConsumer {
return;
}

if (this._connectPromise) {
await this._connectPromise;
return;
}

const options = mergeConnectParams(connectParams, this._connectParams);

this._adapter = await AMQPAdapter.connect(options);
this._adapter._errorHandler = this._errorHandler;
this._connectPromise = AMQPAdapter.connect(options);
this._adapter = await this._connectPromise;
this._connectPromise = null;

this._adapter._errorHandler = this._errorHandler;
await this._onInit();
return this;
}
Expand Down

0 comments on commit 937f70c

Please sign in to comment.