Skip to content

Commit 008f3a1

Browse files
committed
Add _has_floating_child
1 parent 637cae3 commit 008f3a1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

autoload/vital/__vital__/Async/Promise.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let s:NOOP = funcref('s:noop')
3838

3939
let s:PROMISE = {
4040
\ '_state': s:PENDING,
41+
\ '_has_floating_child': v:false,
4142
\ '_children': [],
4243
\ '_fulfillments': [],
4344
\ '_rejections': [],
@@ -90,7 +91,7 @@ function! s:_publish(promise, ...) abort
9091
endif
9192

9293
if empty(a:promise._children)
93-
if settled == s:REJECTED
94+
if settled == s:REJECTED && !a:promise._has_floating_child
9495
call s:_on_unhandled_rejection(a:promise._result)
9596
endif
9697
return
@@ -285,8 +286,10 @@ function! s:_promise_then(...) dict abort
285286
let l:Res = a:0 > 0 ? a:1 : v:null
286287
let l:Rej = a:0 > 1 ? a:2 : v:null
287288
if state == s:FULFILLED
289+
let parent._has_floating_child = v:true
288290
call s:Later.call(funcref('s:_invoke_callback', [state, child, Res, parent._result]))
289291
elseif state == s:REJECTED
292+
let parent._has_floating_child = v:true
290293
call s:Later.call(funcref('s:_invoke_callback', [state, child, Rej, parent._result]))
291294
else
292295
call s:_subscribe(parent, child, Res, Rej)

test/Async/Promise.vimspec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,15 @@ Describe Async.Promise
860860
Assert Equals(error, result)
861861
End
862862

863+
It should not call when promise catched
864+
let l = l:
865+
call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
866+
867+
let p = P.reject({ 'error': 'error' }).catch({ -> {} })
868+
call P.wait(Wait(100))
869+
Assert KeyNotExists(l, 'result')
870+
End
871+
863872
It should not call when promise catched
864873
let l = l:
865874
call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })

0 commit comments

Comments
 (0)