dolphindb 2.0.525 → 2.0.526

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -380,7 +380,8 @@ export declare class DDB {
380
380
  parse_object: boolean;
381
381
  /** DdbMessage listeners */
382
382
  listeners: DdbMessageListener[];
383
- promise: Promise<any>;
383
+ pconnect: Promise<void>;
384
+ presult: Promise<any>;
384
385
  get connected(): boolean;
385
386
  /**
386
387
  Initialize an instance of DolphinDB Client using the WebSocket URL
package/index.js CHANGED
@@ -1945,7 +1945,8 @@ class DDB {
1945
1945
  this.parse_object = true;
1946
1946
  /** DdbMessage listeners */
1947
1947
  this.listeners = [];
1948
- this.promise = Promise.resolve(null);
1948
+ this.pconnect = Promise.resolve();
1949
+ this.presult = Promise.resolve(null);
1949
1950
  this.url = url;
1950
1951
  if (options.autologin !== undefined)
1951
1952
  this.autologin = options.autologin;
@@ -2066,7 +2067,8 @@ class DDB {
2066
2067
  if (this.connected)
2067
2068
  this.websocket.close(1000);
2068
2069
  this.on_message = () => { };
2069
- this.promise = Promise.resolve(null);
2070
+ this.presult = Promise.resolve(null);
2071
+ this.pconnect = Promise.resolve();
2070
2072
  }
2071
2073
  /** rpc through websocket (function/script/variable command)
2072
2074
  - type: API 类型: 'script' | 'function' | 'variable'
@@ -2078,8 +2080,21 @@ class DDB {
2078
2080
  为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
2079
2081
  */
2080
2082
  async rpc(type, { script, func, args = [], vars = [], urgent, listener, parse_object, }) {
2081
- if (!this.websocket)
2082
- await this.connect();
2083
+ if (!this.websocket) {
2084
+ const ptail = this.pconnect;
2085
+ let resolve;
2086
+ this.pconnect = new Promise((_resolve, _reject) => {
2087
+ resolve = _resolve;
2088
+ });
2089
+ await ptail;
2090
+ try {
2091
+ if (!this.websocket)
2092
+ await this.connect();
2093
+ }
2094
+ finally {
2095
+ resolve();
2096
+ }
2097
+ }
2083
2098
  if (!this.connected)
2084
2099
  throw new Error(`${this.url} is already disconnected`);
2085
2100
  // this 上的当前配置需要在 message 到达后使用,先保存起来
@@ -2089,10 +2104,10 @@ class DDB {
2089
2104
  // 违反世界观可能造成:
2090
2105
  // 1. 并发多个请求只返回第一个结果(阻塞,需后续请求疏通)
2091
2106
  // 2. windows 下 ddb server 返回多个相同的结果
2092
- const ptail = this.promise;
2107
+ const ptail = this.presult;
2093
2108
  let resolve;
2094
2109
  let reject;
2095
- const promise = this.promise = new Promise((_resolve, _reject) => {
2110
+ const presult = this.presult = new Promise((_resolve, _reject) => {
2096
2111
  resolve = _resolve;
2097
2112
  reject = _reject;
2098
2113
  });
@@ -2153,7 +2168,7 @@ class DDB {
2153
2168
  command,
2154
2169
  ...args.map((arg) => arg.pack())
2155
2170
  ]));
2156
- return promise;
2171
+ return presult;
2157
2172
  }
2158
2173
  /** eval script through websocket (script command)
2159
2174
  - script?: Script to execute