Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attach-errback now returns a promise, finished with the return value of the errback. introducing `promisify` which turns any val (or multiple values) into a promise object, catching errors as it goes along: (promisify (values 1 2 3)) => promise with values (1 2 3) (promisify (error "oh crap")) => promise with errored T improving error chaining. previously, errors were not propagating like values were. this has been updated so that an errback at the bottom (or top in lisp) of the chain can catch errors for the entire chain. introducing `catcher` macro, which essentially replaces promise-handler-case. instead of wrapping lexical forms, we now rely on error chaining. this is nicer because we dont just need access to the lexical form, any other form that returns a promise can be caaught. introducing `finally` macro, which runs its body form whether the given promise is finished or errored, allowing for easy cleanup in a chain no matter the outcome. introducing `with-promise` macro. separates promise creation and resolving from consumption: (with-promise (resolve reject) (as:with-delay (1) (resolve 123))) this is important not just because of separation of creation and consumption, but because with-promise catches errors in the creation process and signals them on the returned promise. adding utility functions: - amap - all - areduce adding chaining helper: (chain 4 (:then (x) (+ 4 x)) (:then (x) (format t "x is ~a~%" x))) yields form: (attach (promisify (attach (promisify 4) (lambda (x) (+ 4 x)))) (lambda (x) (format t "x is ~a~%" x))) (chain 4 (:then (x) (+ x 9)) (:then (x) (list x x x)) (:map (x) (+ x 5)) (:reduce (acc x 0) (+ acc x)) (:then (final) (format t "value is ~a~%" final)) (:catch (e) (format t "error! ~a~%" e))) prints: value is 54 (chain 4 (:then (x) (* x 13)) (:then (y) (list y (1+ y) (+ 5 y))) (:map (x) (+ x 'tst)) (:then (x) (format t "x is ~a~%" x)) (:catch (e) (format t "error! ~a~%" e)) (:finally () (format t "done~%"))) prints: error! The value TST is not of the expected type NUMBER. done introducing the concept of naming promises, although this will probably go away and be replaced with something a bit more helpful.
- Loading branch information