From c6f532d8e1a2b63d91873d1be837ce40d9906e4e Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 20 Jun 2019 13:44:39 -0400 Subject: [PATCH] New file, WIP --- libs/cyclone/futures.scm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 libs/cyclone/futures.scm diff --git a/libs/cyclone/futures.scm b/libs/cyclone/futures.scm new file mode 100644 index 00000000..7171e80e --- /dev/null +++ b/libs/cyclone/futures.scm @@ -0,0 +1,32 @@ +;; Temporary test file for futures +;; See: +;; https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/future? +;; https://purelyfunctional.tv/guide/clojure-concurrency/#future + +(import (scheme base) + (scheme write) + (cyclone concurrency) + (srfi 18) +) + +(define *future-sym* (string->symbol " future ")) +(define (future? obj) + (and (vector? obj) (eq? (vector-ref obj 0) *future-sym*))) + + +;; TODO: macro (future expr ...) + +;; From clojure docs: +; Takes a function of no args and yields a future object that will +; invoke the function in another thread, and will cache the result and +; return it on all subsequent calls to deref/@. If the computation has +; not yet finished, calls to deref/@ will block, unless the variant +; of deref with timeout is used. See also - realized?. + +(define (future-call thunk) + (let ((ftr (vector *future-sym* 'todo))) + ;; TODO: setup and call the thread here + ftr)) + + +TODO: custom deref but eventually need to fold that functionality back into the main one