silence all internal play promises

This commit is contained in:
ydylla
2020-03-23 22:50:19 +01:00
parent 3c127afeb9
commit 71928443f3
6 changed files with 42 additions and 10 deletions

27
src/js/utils/promise.js Normal file
View File

@ -0,0 +1,27 @@
/**
* Returns whether an object is `Promise`-like (i.e. has a `then` method).
*
* @param {Object} value
* An object that may or may not be `Promise`-like.
*
* @return {boolean}
* Whether or not the object is `Promise`-like.
*/
export function isPromise(value) {
return value !== undefined && value !== null && typeof value.then === 'function';
}
/**
* Silence a Promise-like object.
*
* This is useful for avoiding non-harmful, but potentially confusing "uncaught
* play promise" rejection error messages.
*
* @param {Object} value
* An object that may or may not be `Promise`-like.
*/
export function silencePromise(value) {
if (isPromise(value)) {
value.then(null, () => {});
}
}