mattermost-mobile/app/utils/promise_timeout.js
Chris Duarte 7fdb0c4d27 Create post timeout (#1242)
* Add timeout for api calls that take too long

This will allow any api call that takes too long to fail faster.

Specially for Client4.createPost.  If the api never returns the post is in a pending state and the user is not able to retry.

* Add canTimeout flag
2017-12-08 18:19:17 -03:00

16 lines
426 B
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
export function promiseTimeout(promise, ms) {
const timeout = new Promise((resolve, reject) => {
const id = setTimeout(() => {
clearTimeout(id);
reject('Timed out in ' + ms + 'ms.');
}, ms);
});
return Promise.race([
promise,
timeout
]);
}