2
0
mirror of https://github.com/esiur/esiur-js.git synced 2026-04-03 21:48:21 +00:00

Reconnect

This commit is contained in:
2022-08-11 21:27:58 +03:00
parent 78d74d540b
commit 1985363ad7
4 changed files with 250 additions and 255 deletions

View File

@@ -27,6 +27,8 @@
"use strict";
import AsyncException from './AsyncException.js';
import ExceptionCode from './ExceptionCode.js';
import ErrorType from './ErrorType.js';
export default class AsyncReply extends Promise
{
@@ -88,16 +90,24 @@ export default class AsyncReply extends Promise
timeout(milliseconds, onTimeout){
let self = this;
setTimeout(() => {
if (!self.ready && self.exception == null)
onTimeout();
if (!self.ready && self.exception == null){
self.triggerError(ErrorType.Management, ExceptionCode.Timeout, "Execution timeout expired.");
if (onTimeout instanceof Function)
onTimeout();
}
}, milliseconds);
}
trigger(result)
{
if (this.ready)
return;
return this;
if (this.exception != null)
return this;
this.result = result;
this.ready = true;

View File

@@ -34,5 +34,7 @@ export default //const ExceptionCode =
NotAttached: 31,
AlreadyListened: 32,
AlreadyUnlistened: 33,
NotListenable: 34
NotListenable: 34,
ParseError: 35,
Timeout: 36
};