* 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
16 lines
426 B
JavaScript
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
|
|
]);
|
|
}
|