Skip to content

Commit 637cae3

Browse files
committed
Fix for reviews
- Add docs for clear callback - Add docs for callback signature - Add tests for rejected promsie, resolved promise,
1 parent ae5e38c commit 637cae3

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

doc/vital/Async/Promise.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,15 @@ on_unhandled_rejection({callback}) *Vital.Async.Promise.on_unhandled_rejection*
381381

382382
Set callback to catch all unhandled rejected promise's result.
383383

384+
The {callback} is |Funcref|, it's argument can be unhandled thrown error or unhandled rejected value.
385+
384386
Note:
385387
This callback will called even if you using |Vital.Async.Promise.wait()|.
388+
If you want to clear callback, you can use following codes.
386389

390+
>
391+
call Promise.on_unhandled_rejection(Promise.noop)
392+
<
387393

388394
is_promise({value}) *Vital.Async.Promise.is_promise()*
389395

test/Async/Promise.vimspec

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,12 @@ Describe Async.Promise
806806
End
807807

808808
Describe .on_unhandled_rejection
809-
It should call when promsie does not catch
809+
810+
After each
811+
call P.on_unhandled_rejection(P.noop)
812+
End
813+
814+
It should call when promise throw error but unhandled
810815
let l = l:
811816
call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
812817

@@ -816,6 +821,16 @@ Describe Async.Promise
816821
Assert HasKey(result, 'throwpoint')
817822
End
818823

824+
It should call when promise rejected but unhandled
825+
let l = l:
826+
call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
827+
828+
let p = P.reject({ 'error': 'error' })
829+
call s:wait_has_key(l, 'result')
830+
Assert HasKey(result, 'error')
831+
Assert Equals(result.error, 'error')
832+
End
833+
819834
It should call when promise does not catch with finally
820835
let l = l:
821836
call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
@@ -853,6 +868,15 @@ Describe Async.Promise
853868
call P.wait(Wait(100))
854869
Assert KeyNotExists(l, 'result')
855870
End
871+
872+
It should not call when promise does not throw error
873+
let l = l:
874+
call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
875+
876+
let p = P.resolve().then({ -> { 'success': 'success' } })
877+
call P.wait(Wait(100))
878+
Assert KeyNotExists(l, 'result')
879+
End
856880
End
857881
End
858882

0 commit comments

Comments
 (0)