From: Christopher Allan Webber Date: Wed, 14 Dec 2016 23:41:50 +0000 (-0600) Subject: agenda: Add 8usleep. X-Git-Tag: v0.3.0~9 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=19ecc5f415fac9713aa2b037926ab80e95f75197;p=8sync.git agenda: Add 8usleep. * 8sync/agenda.scm (8usleep): New variable. (8sleep): Update to refer to argument as "secs" rather than "time". --- diff --git a/8sync/agenda.scm b/8sync/agenda.scm index da578a7..9884afc 100644 --- a/8sync/agenda.scm +++ b/8sync/agenda.scm @@ -471,11 +471,25 @@ forge ahead in our current function!" (make-run-request (lambda () body ...) #f)))))) ;; TODO: Rewrite when we move to this being just `sleep'. -(define (8sleep time) +(define (8sleep secs) + "Like sleep, but asynchronous." (8sync-abort-to-prompt (make-async-request (lambda (kont) - (make-run-request (lambda () (kont #f)) (tdelta time)))))) + (make-run-request (lambda () (kont #f)) (tdelta secs)))))) + +(define (8usleep usecs) + "Like usleep, but asynchronous." + (define (usecs->time-pair) + (if (< 1000000) + (cons 0 usecs) + (let* ((sec (floor (/ usecs 1000000))) + (msec (- usecs (* sec 1000000)))) + (cons sec msec)))) + (8sync-abort-to-prompt + (make-async-request + (lambda (kont) + (make-run-request (lambda () (kont #f)) (tdelta usecs->time-pair)))))) ;; Voluntarily yield execution (define (yield) ; @@: should this be define-inlinable?