Xo#call(method, args).retry(predicate)

This commit is contained in:
Julien Fontanet 2016-01-22 17:47:35 +01:00
parent 749d5e22bb
commit 85d0271b86

View File

@ -37,14 +37,22 @@ export default class Xo extends JsonRpcWebSocketClient {
return this._user return this._user
} }
call (method, args) { call (method, args, i) {
return new Promise(resolve => { if (startsWith(method, 'session.')) {
if (startsWith(method, 'session.')) { return Promise.reject(
throw new XoError('session.*() methods are disabled from this interface') new XoError('session.*() methods are disabled from this interface')
} )
}
resolve(super.call(method, args)) const promise = super.call(method, args)
promise.retry = predicate => promise.catch(error => {
i = (i || 0) + 1
if (predicate(error, i)) {
return this.call(method, args, i)
}
}) })
return promise
} }
signIn (credentials) { signIn (credentials) {