aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/promise.js
diff options
context:
space:
mode:
authorydylla <ydylla@gmail.com>2020-03-23 22:50:19 +0100
committerydylla <ydylla@gmail.com>2020-03-23 22:56:32 +0100
commit71928443f317e624ab94ff18e207447f06f745ad (patch)
tree7dde5788b1f4e425527df136566d275960fc03f5 /src/js/utils/promise.js
parent3c127afeb9e0059d1352ecb5b790633177a70cc4 (diff)
downloadplyr-71928443f317e624ab94ff18e207447f06f745ad.tar.lz
plyr-71928443f317e624ab94ff18e207447f06f745ad.tar.xz
plyr-71928443f317e624ab94ff18e207447f06f745ad.zip
silence all internal play promises
Diffstat (limited to 'src/js/utils/promise.js')
-rw-r--r--src/js/utils/promise.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/js/utils/promise.js b/src/js/utils/promise.js
new file mode 100644
index 00000000..42fcc2c3
--- /dev/null
+++ b/src/js/utils/promise.js
@@ -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, () => {});
+ }
+}