agenda: Fixing exports.
[8sync.git] / 8sync / agenda.scm
index 223900814e68f9be3c32e4ae405d71d489a9c8ea..b41500dec5f502ce6a2d6188f3a2ceb4b056bbe7 100644 (file)
 
             run-it wrap wrap-apply run run-at run-delay
 
-            8sync-delay
-            8sync-run 8sync-run-at 8sync-run-delay
             8sync
-            8sleep
+            8sleep 8usleep
             
             ;; used for introspecting the error, but a method for making
             ;; is not exposed
@@ -78,8 +76,6 @@
             %current-agenda
             start-agenda agenda-run-once))
 
-(install-suspendable-ports!)
-
 ;; @@: Using immutable agendas here, so wouldn't it make sense to
 ;;   replace this queue stuff with using pfds based immutable queues?
 
@@ -473,11 +469,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 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)) time)))))
+      (make-run-request (lambda () (kont #f)) (tdelta usecs->time-pair))))))
 
 ;; Voluntarily yield execution
 (define (yield)  ; @@: should this be define-inlinable?
@@ -617,6 +627,7 @@ on suspendable ports."
                        (post-run-hook #f))
   ;; TODO: Document fields
   "Start up the AGENDA"
+  (install-suspendable-ports!)
   (let loop ((agenda agenda))
     (let ((agenda   
            ;; @@: Hm, maybe here would be a great place to handle