Skip to content

Instantly share code, notes, and snippets.

@ralt
Last active Jan 17, 2021
Embed
What would you like to do?
Parenscript async/await support
(ps::defprinter ps-js::await (x)
(ps::psw (string-downcase "(await "))
(ps::print-op-argument 'ps-js::await x)
(ps::psw ")"))
(ps::define-trivial-special-ops
await ps-js::await)
(ps::define-statement-operator async-defun (name lambda-list &rest body)
(multiple-value-bind (effective-args body-block docstring)
(ps::compile-named-function-body name lambda-list body)
(list 'ps-js::async-defun name effective-args docstring body-block)))
(ps::defprinter ps-js::async-defun (name args docstring body-block)
(when docstring (ps::print-comment docstring))
(ps::psw "async ")
(ps::print-fun-def name args body-block))
(ps::define-expression-operator async-lambda (lambda-list &rest body)
(multiple-value-bind (effective-args effective-body)
(ps::parse-extended-function lambda-list body)
`(ps-js::async-lambda
,effective-args
,(let ((ps::*function-block-names* ()))
(ps::compile-function-body effective-args effective-body)))))
(ps::defprinter ps-js::async-lambda (args body-block)
(ps::parenthesize-at-toplevel
(lambda ()
(ps::psw "async ")
(ps::print-fun-def nil args body-block))))
@ralt

This comment has been minimized.

Copy link
Owner Author

@ralt ralt commented Aug 20, 2019

To be used as such:

(async-defun foo ()
  ...)

And:

(let ((bar (await (foo))))
  ...)

And:

(async-lambda () (await (foo)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment