aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/promise.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-03-29 11:18:08 +1100
committerGitHub <noreply@github.com>2020-03-29 11:18:08 +1100
commit2f26c80c8884911db7029b8f9fcf4e8e0c5e57d6 (patch)
treebb14cbfd13f3006fc0e7a73248ff8c07947d5ff8 /src/js/utils/promise.js
parentbe3ffc1f96ea830ad77d3cc4213b700ad91c416c (diff)
parent6a1d6f13a2581228b6ec64887bef4be8f9fed2b0 (diff)
downloadplyr-2f26c80c8884911db7029b8f9fcf4e8e0c5e57d6.tar.lz
plyr-2f26c80c8884911db7029b8f9fcf4e8e0c5e57d6.tar.xz
plyr-2f26c80c8884911db7029b8f9fcf4e8e0c5e57d6.zip
Merge pull request #1739 from ydylla/ignore-internal-play-promises
Ignore 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, () => {});
+ }
+}