mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
cqi-js: implement timeout
This commit is contained in:
parent
c52c966863
commit
e21ef2422d
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user