diff --git a/eager-future2.asd b/eager-future2.asd index 133ae4cdc83cb0df1fe8dccbb7dd52b14685e27a..fd7c3c1dbc1d1f0e6402b6c0007aedf879c124c9 100644 --- a/eager-future2.asd +++ b/eager-future2.asd @@ -6,5 +6,6 @@ :components ((:file "package") (:file "scheduler") (:file "make-future") - (:file "future")) + (:file "future") + (:file "library")) :depends-on (:bordeaux-threads :trivial-garbage)) diff --git a/library.lisp b/library.lisp new file mode 100644 index 0000000000000000000000000000000000000000..ffd344e9e12af7dc917ea0012c03d9aef6845e93 --- /dev/null +++ b/library.lisp @@ -0,0 +1,26 @@ +(in-package #:eager-future2) + +(defmacro pexec (&body body) + "A shorthand for (pcall (lambda () ...))." + `(pcall (lambda () ,@body))) + +(defmacro plet ((&rest bindings) &body body) + "Like LET, but all bindings are evaluated asynchronously." + (let ((bindings (mapcar (lambda (x) (if (consp x) x (list x nil))) + bindings))) + (let ((syms (mapcar (lambda (x) (gensym (string (car x)))) + bindings))) + `(let ,(loop for (nil exp) in bindings + for sym in syms + collect `(,sym (pexec ,exp))) + (symbol-macrolet ,(loop for (var nil) in bindings + for sym in syms + collect `(,var (yield ,sym))) + ,@body))))) + +;;(defun pand) + +;;(defun por) + +(defun select-timeout (timeout &rest futures) + (apply #'select (pcall (lambda () (sleep timeout)) :eager) futures)) \ No newline at end of file diff --git a/make-future.lisp b/make-future.lisp index 778e2d853bef7a25c28e58db349a9f6cfd937ed0..e95e34b31e48211397e375e31ab253fa0e2346e8 100644 --- a/make-future.lisp +++ b/make-future.lisp @@ -69,21 +69,3 @@ The function is called in an unspecified dynamic environment." (unless (eq future-type :lazy) (schedule-future future future-type)) future)) - -(defmacro pexec (&body body) - "A shorthand for (pcall (lambda () ...))." - `(pcall (lambda () ,@body))) - -(defmacro plet ((&rest bindings) &body body) - "Like LET, but all bindings are evaluated asynchronously." - (let ((bindings (mapcar (lambda (x) (if (consp x) x (list x nil))) - bindings))) - (let ((syms (mapcar (lambda (x) (gensym (string (car x)))) - bindings))) - `(let ,(loop for (nil exp) in bindings - for sym in syms - collect `(,sym (pexec ,exp))) - (symbol-macrolet ,(loop for (var nil) in bindings - for sym in syms - collect `(,var (yield ,sym))) - ,@body)))))