From 1a0ec7db47721a0fc82ae64456100457448148a3 Mon Sep 17 00:00:00 2001 From: Eryn Lynn Date: Sun, 22 Sep 2019 22:58:23 -0400 Subject: [PATCH] Make Promise.is only check andThennable --- CHANGELOG.md | 4 ++++ lib/README.md | 2 +- lib/init.lua | 7 +------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af967f0..05e6bdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.4.0 + +- `Promise.is` now only checks if the object is "andThennable" (has an `andThen` method). + # 2.3.1 - Make unhandled rejection warning trigger on next Heartbeat diff --git a/lib/README.md b/lib/README.md index 892bf42..3a89d8c 100644 --- a/lib/README.md +++ b/lib/README.md @@ -186,7 +186,7 @@ docs: params: "promises: array>" returns: Promise - name: is - desc: Returns whether the given object is a Promise. + desc: Returns whether the given object is a Promise. This only checks if the object is a table and has an `andThen` method. static: true params: "object: any" returns: diff --git a/lib/init.lua b/lib/init.lua index 492d625..88f2bd9 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -67,8 +67,6 @@ local function createSymbol(name) return symbol end -local PromiseMarker = createSymbol("PromiseMarker") - local Promise = {} Promise.prototype = {} Promise.__index = Promise.prototype @@ -101,9 +99,6 @@ function Promise.new(callback, parent) -- Used to locate where a promise was created _source = debug.traceback(), - -- A tag to identify us as a promise - [PromiseMarker] = true, - _status = Promise.Status.Started, -- A table containing a list of all results, whether success or failure. @@ -300,7 +295,7 @@ function Promise.is(object) return false end - return object[PromiseMarker] == true + return type(object.andThen) == "function" end --[[