hypha-rpc 0.20.33 → 0.20.35

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.
@@ -251,7 +251,7 @@ class Timer {
251
251
  }
252
252
 
253
253
  clear() {
254
- if (this._task) {
254
+ if (this._task && this.started) {
255
255
  clearTimeout(this._task);
256
256
  this._task = null;
257
257
  this.started = false;
@@ -859,13 +859,13 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
859
859
  } catch (error) {
860
860
  console.error("Error in callback:", method_id, error);
861
861
  } finally {
862
+ if (timer && timer.started) {
863
+ timer.clear();
864
+ }
862
865
  if (clear_after_called && self._object_store[session_id]) {
863
866
  // console.log("Deleting session", session_id, "from", self._client_id);
864
867
  delete self._object_store[session_id];
865
868
  }
866
- if (timer && timer.started) {
867
- timer.clear();
868
- }
869
869
  }
870
870
  };
871
871
 
@@ -1087,27 +1087,37 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1087
1087
  }
1088
1088
  const total_size = message_package.length;
1089
1089
  if (total_size <= CHUNK_SIZE + 1024) {
1090
- self._emit_message(message_package).then(function () {
1091
- if (timer) {
1092
- // console.log(`Start watchdog timer.`);
1093
- // Only start the timer after we send the message successfully
1094
- timer.start();
1095
- }
1096
- });
1090
+ self
1091
+ ._emit_message(message_package)
1092
+ .then(function () {
1093
+ if (timer) {
1094
+ // If resolved successfully, reset the timer
1095
+ timer.reset();
1096
+ }
1097
+ })
1098
+ .catch(function (err) {
1099
+ console.error("Failed to send message", err);
1100
+ reject(err);
1101
+ if (timer) {
1102
+ timer.clear();
1103
+ }
1104
+ });
1097
1105
  } else {
1098
1106
  // send chunk by chunk
1099
1107
  self
1100
1108
  ._send_chunks(message_package, target_id, remote_parent)
1101
1109
  .then(function () {
1102
1110
  if (timer) {
1103
- // console.debug(`Start watchdog timer.`);
1104
- // Only start the timer after we send the message successfully
1105
- timer.start();
1111
+ // If resolved successfully, reset the timer
1112
+ timer.reset();
1106
1113
  }
1107
1114
  })
1108
1115
  .catch(function (err) {
1109
1116
  console.error("Failed to send message", err);
1110
1117
  reject(err);
1118
+ if (timer) {
1119
+ timer.clear();
1120
+ }
1111
1121
  });
1112
1122
  }
1113
1123
  });