diff --git a/TODO b/TODO --- a/TODO +++ b/TODO @@ -1,7 +1,9 @@ -* Use async/await +* Use Parenscript's packages * Use Parenscript's minifier -* WAIT and MENU with async/await +* Remove dots +* MENU with async/await +* Find a way to minify syntax (extra returns at least) * Special locations * Special variables * CLI build for Linux diff --git a/src/api.ps b/src/api.ps --- a/src/api.ps +++ b/src/api.ps @@ -24,6 +24,9 @@ (defm (root api report-error) (text) (alert text)) +(defm (root api sleep) (msec) + (ps:new (*promise (ps:=> resolve (set-timeout resolve msec))))) + (defm (root api init-dom) () ;; Save/load buttons (let ((btn (document.get-element-by-id "qsp-btn-save"))) diff --git a/src/intrinsic-macros.lisp b/src/intrinsic-macros.lisp --- a/src/intrinsic-macros.lisp +++ b/src/intrinsic-macros.lisp @@ -147,6 +147,9 @@ ;;; 20time +(ps:defpsmacro wait (msec) + `(await (api-call sleep ,msec))) + (ps:defpsmacro settimer (interval) `(api-call set-timer ,interval)) diff --git a/src/intrinsics.ps b/src/intrinsics.ps --- a/src/intrinsics.ps +++ b/src/intrinsics.ps @@ -274,12 +274,6 @@ ;;; 20time -;; I wonder if there's a better solution than busy-wait -(defm (root lib wait) (msec) - (let* ((now (ps:new (*date))) - (exit-time (+ (funcall now.get-time) msec))) - (loop :while (< (funcall now.get-time) exit-time)))) - (defm (root lib msecscount) () (- (*date.now) (root started-at))) diff --git a/src/ps-macros.lisp b/src/ps-macros.lisp --- a/src/ps-macros.lisp +++ b/src/ps-macros.lisp @@ -64,7 +64,7 @@ (ps:defpsmacro location ((name) &body body) `(setf (root locs ,name) - (lambda (args) + (ps:async-lambda (args) (label-block () (api-call init-args args) ,@body