From e21ef2422da3c78356d0a9eb2251ca9dde6225a9 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Fri, 30 Jun 2023 14:13:34 +0200
Subject: [PATCH] cqi-js: implement timeout
---
app/static/js/cqi/api/client.js | 12 +++++++-----
app/static/js/cqi/client.js | 6 +++---
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/app/static/js/cqi/api/client.js b/app/static/js/cqi/api/client.js
index e68dfa96..f3c41715 100644
--- a/app/static/js/cqi/api/client.js
+++ b/app/static/js/cqi/api/client.js
@@ -2,12 +2,12 @@ cqi.api.APIClient = class APIClient {
/**
* @param {string} host
* @param {string} corpusId
- * @param {number} [timeout=Infinity] timeout
+ * @param {number} [timeout=60] timeout
* @param {string} [version=0.1] version
*/
- constructor(host, corpus_id, timeout = Infinity, version = '0.1') {
+ constructor(host, corpus_id, timeout = 60, version = '0.1') {
this.host = host;
- this.timeout = timeout;
+ this.timeout = timeout * 1000; // convert seconds to milliseconds
this.version = version;
this.socket = io(
this.host,
@@ -26,8 +26,10 @@ cqi.api.APIClient = class APIClient {
*/
#request(fn_name, fn_args = {}) {
return new Promise((resolve, reject) => {
- // TODO: implement this.socket.timeout(this.timeout).emit(...)
- this.socket.emit('cqi', {fn_name: fn_name, fn_args: fn_args}, (response) => {
+ this.socket.timeout(this.timeout).emit('cqi', {fn_name: fn_name, fn_args: fn_args}, (timeoutError, response) => {
+ if (timeoutError) {
+ reject(timeoutError);
+ }
if (response.code === 200) {
resolve(response.payload);
}
diff --git a/app/static/js/cqi/client.js b/app/static/js/cqi/client.js
index dec54c86..7a92a904 100644
--- a/app/static/js/cqi/client.js
+++ b/app/static/js/cqi/client.js
@@ -2,12 +2,12 @@ cqi.CQiClient = class CQiClient {
/**
* @param {string} host
* @param {string} corpusId
- * @param {number} [timeout=Infinity] timeout
+ * @param {number} [timeout=60] timeout
* @param {string} [version=0.1] version
*/
- constructor(host, corpusId, timeout = Infinity, version = '0.1') {
+ constructor(host, corpusId, timeout = 60, version = '0.1') {
/** @type {cqi.api.APIClient} */
- this.api = new cqi.api.APIClient(host, corpusId, version);
+ this.api = new cqi.api.APIClient(host, corpusId, timeout, version);
}
/**