Skip to content

Commit

Permalink
release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Apr 18, 2020
1 parent a6ec7ef commit 987a3dc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Change log
==========

1.2.0 (2020-04-16)
1.2.0 (2020-04-20)
------------------

* Connection re-open after critical server errors
* Error code string representation added to error object
* Pool improvements

1.1.0 (2020-04-14)
------------------
Expand Down
3 changes: 2 additions & 1 deletion lib/wrapper/sapnwrfc-pool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export declare class Pool {
private __connectionParams;
private __poolOptions;
private __clientOptions;
private __fillRequests;
private __clients;
constructor(connectionParams: RfcConnectionParameters, poolOptions?: RfcPoolOptions, clientOptions?: RfcClientOptions);
newClient(): Client;
fill(): void;
refill(): void;
acquire(): Promise<Client>;
release(client: Client): Promise<void>;
releaseAll(): Promise<number>;
Expand Down
15 changes: 11 additions & 4 deletions lib/wrapper/sapnwrfc-pool.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/wrapper/sapnwrfc-pool.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"devDependencies": {
"@babel/core": "^7.9.0",
"@types/bluebird": "^3.5.30",
"@types/node": "^13.11.1",
"@types/node": "^13.13.0",
"async": "^3.2.0",
"cmake-js": "^6.1.0",
"decimal.js": "^10.2.0",
Expand Down
19 changes: 15 additions & 4 deletions src/ts/wrapper/sapnwrfc-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Pool {
private __connectionParams: RfcConnectionParameters;
private __poolOptions: RfcPoolOptions;
private __clientOptions: RfcClientOptions | undefined;
private __fillRequests: number;

private __clients: {
ready: Array<Client>;
Expand All @@ -34,6 +35,7 @@ export class Pool {
this.__connectionParams = connectionParams;
this.__poolOptions = poolOptions;
this.__clientOptions = clientOptions;
this.__fillRequests = 0;
this.__clients = {
ready: [],
active: new Map(),
Expand All @@ -46,14 +48,23 @@ export class Pool {
: new Client(this.__connectionParams);
}

fill() {
refill() {
if (
this.__clients.ready.length + this.__fillRequests >=
this.__poolOptions.min
) {
return;
}

this.__fillRequests++;
const client = this.newClient();
client.connect((err) => {
this.__fillRequests--;
if (isUndefined(err)) {
if (this.__clients.ready.length < this.__poolOptions.min) {
this.__clients.ready.unshift(client);
if (this.__clients.ready.length < this.__poolOptions.min)
this.fill();
this.refill();
} else {
client.close(() => {});
}
Expand All @@ -68,7 +79,7 @@ export class Pool {
(resolve: (arg: Client) => void, reject: (arg: any) => void) => {
const client = this.__clients.ready.pop();
if (this.__clients.ready.length < this.__poolOptions.min)
this.fill();
this.refill();
if (client instanceof Client) {
this.__clients.active.set(client.id, client);
resolve(client);
Expand Down Expand Up @@ -103,7 +114,7 @@ export class Pool {
client.close(() => {
this.__clients.active.delete(id);
if (this.__clients.ready.length < this.__poolOptions.min) {
this.fill();
this.refill();
}
resolve(id);
});
Expand Down

0 comments on commit 987a3dc

Please sign in to comment.