Skip to content

Commit

Permalink
promise-chain: allow (catch) clause and return promise
Browse files Browse the repository at this point in the history
  • Loading branch information
bendlas committed Jun 7, 2019
1 parent 7ac038c commit a3b6837
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/promise-examples.el
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ and resolves it in the output result."
(then (lambda (result)
(message "grep result:\n%s" result)))

(promise-catch (lambda (reason)
(message "promise-catch: %s" reason)))))
(catch (lambda (reason)
(message "promise-catch: %s" reason)))))

(defun example15 ()
"An example when `make-process' returns an error."
Expand Down
19 changes: 15 additions & 4 deletions promise.el
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@
(lambda (value)
...))
(promise-catch
(catch
(lambda (reason)
...))
(done
(lambda (value)
...)))
...))
(finally
(lambda () ...))
as below.
Expand All @@ -125,7 +128,12 @@ as below.
(setf promise (promise-done promise
(lambda (reason)
...))))"
...)))
(setf promise (promise-finally promise
(lambda ()
...)))
promise)"
(declare (indent 1) (debug t))
`(let ((promise ,(car body)))
,@(mapcar (lambda (sexp)
Expand All @@ -139,6 +147,8 @@ as below.
promise-done
promise-finally)
`(setf promise (,fn promise ,@args)))
(catch
`(setf promise (promise-catch promise ,@args)))
(then
`(setf promise (promise-then promise ,@args)))
(done
Expand All @@ -147,7 +157,8 @@ as below.
`(setf promise (promise-finally promise ,@args)))
(otherwise
sexp))))
(cdr body))))
(cdr body))
promise))

;;
;; Promise version of various utility functions
Expand Down

0 comments on commit a3b6837

Please sign in to comment.