diff options
Diffstat (limited to 'lang/js/src')
-rw-r--r-- | lang/js/src/Connection.js | 8 | ||||
-rw-r--r-- | lang/js/src/index.js | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js index 4055da6a..d43d55f1 100644 --- a/lang/js/src/Connection.js +++ b/lang/js/src/Connection.js @@ -74,11 +74,15 @@ export class Connection{ * Retrieves the information about the backend. * @param {Boolean} details (optional) If set to false, the promise will * just return if a connection was successful. + * @param {Number} timeout (optional) * @returns {Promise<backEndDetails>|Promise<Boolean>} Details from the * backend * @async */ - checkConnection (details = true){ + checkConnection (details = true, timeout = 1000){ + if (typeof timeout !== 'number' && timeout <= 0) { + timeout = 1000; + } const msg = createMessage('version'); if (details === true) { return this.post(msg); @@ -90,7 +94,7 @@ export class Connection{ new Promise(function (resolve, reject){ setTimeout(function (){ reject(gpgme_error('CONN_TIMEOUT')); - }, 500); + }, timeout); }) ]).then(function (){ // success resolve(true); diff --git a/lang/js/src/index.js b/lang/js/src/index.js index c52460cc..b8e4274d 100644 --- a/lang/js/src/index.js +++ b/lang/js/src/index.js @@ -31,13 +31,17 @@ import { Connection } from './Connection'; * connection once, and then offers the available functions as method of the * response object. * An unsuccessful attempt will reject as a GPGME_Error. + * @param {Object} config (optional) configuration options + * @param {Number} config.timeout set the timeout for the initial connection + * check. On some machines and operating systems a default timeout of 500 ms is + * too low, so a higher number might be attempted. * @returns {Promise<GpgME>} * @async */ -function init (){ +function init ({ timeout = 500 } = {}){ return new Promise(function (resolve, reject){ const connection = new Connection; - connection.checkConnection(false).then( + connection.checkConnection(false, timeout).then( function (result){ if (result === true) { resolve(new GpgME()); |