;;; make-future and alet are part of the cl-async-future package
(defun timer (seconds &key threaded)
"Fire an asynchronous timer"
(let ((future (make-future)))
(as:delay (lambda () (finish future t)) :time seconds))
future))
(as:with-event-loop ()
(format t "starting timer!~%")
(alet ((done (timer 2)))
;; 2s pause
(format t "done!~%")))
Here's we run an asynchronous operation which would normally need a callback, and replace it with what looks like real lisp code (in this case "alet").
cl-async-future comes with a full set of macros to abstract asynchronous programming and make it more natural (including error handling).
cl-async-future has been superseded by blackbird.
Topics: obsolete