Skip to content

Commit

Permalink
Update promise.yue
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmolot committed Jul 22, 2024
1 parent 31c55cb commit d24c776
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions promise.yue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
import Error, TypeError, RuntimeError, PromiseError, isfunction, istable, isstring, getmetatable, pcall, xpcall, error, ipairs from gpm.environment
import format, match from gpm.environment.string
_G = _G
import environment from _G.gpm
import Error, TypeError, RuntimeError, PromiseError, isfunction, istable, isstring, getmetatable, pcall, xpcall, error, ipairs, iserror from environment
import create, resume, yield, running from coroutine
import remove from gpm.environment.table
import format, match from environment.string
import remove from environment.table
import captureStack from Error

setTimeout = timer.Simple

Expand All @@ -33,7 +36,7 @@ iscallable = (obj) ->
return true

meta = getmetatable obj
return meta and meta.__call and true or false
return meta and meta.__call and true or false

getThenable = (obj) ->
thenFn = obj.Then or obj.next
Expand Down Expand Up @@ -111,7 +114,7 @@ class Promise
finalize = =>
if @state == STATE_PENDING
return

setTimeout 0, ->
queue = @queue
index = 1
Expand Down Expand Up @@ -205,7 +208,7 @@ class Promise
if file and line
err = RuntimeError( message, file, line, 4 )

if Error.is( err )
if iserror( err )
stack = err.stack
length = #stack

Expand Down Expand Up @@ -236,7 +239,7 @@ class Promise
return (...) ->
p = Promise!

CALL_STACK[] = Error.captureStack() -- push stack
CALL_STACK[] = captureStack! -- push stack

co = create (...) ->
success, result = xpcall( fn, transformError, ... )
Expand All @@ -263,7 +266,7 @@ class Promise
resume co, success, value
else
_success, _value = success, value

wait = ->
if _success != nil
return _success, _value
Expand All @@ -284,7 +287,7 @@ class Promise
else
Then( p, onResolve, onReject )
return wait!

thenable = istable(p) and getThenable(p)
if iscallable( thenable )
pcall( thenable, p, onResolve, onReject )
Expand Down

0 comments on commit d24c776

Please sign in to comment.