Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
230 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
;; Async Example | ||
|
||
local channel-in = async.chan() | ||
local channel-out = async.chan() | ||
|
||
thread.future(function(cin cout) | ||
while true do | ||
local value = async.take!!(cin) | ||
if value then | ||
println("Putting Value: " value) | ||
async.put!!(cout value) | ||
else | ||
println("Ending Thread...") | ||
async.close!(cout) | ||
return nil | ||
end | ||
end | ||
end channel-in channel-out) | ||
|
||
thread.future(function(cin) | ||
|
||
async.put!!(cin "Hello") | ||
async.put!!(cin "World") | ||
async.close!(cin) | ||
|
||
end channel-in) | ||
|
||
local loop? = true | ||
while loop? do | ||
local value = async.take!!(channel-out) | ||
if value then | ||
println("Took Value: " value) | ||
else | ||
loop? = false | ||
end | ||
end | ||
|
||
println("Finished!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
;; Testing | ||
|
||
|
||
c = async.chan() | ||
fc = thread.future(function(c) | ||
async.put!(c 42) | ||
end c) | ||
|
||
p = promise.new() | ||
f = thread.future(function(p) | ||
println("hello " thread.id() " world!") | ||
promise.deliver(p 42) | ||
return 42 | ||
end p) | ||
|
||
d = thread.delay(function() | ||
println("I Processed This") | ||
return 10 | ||
end) | ||
|
||
println("Started!") | ||
println("Future Value : " deref(f)) | ||
println("Delay Value : " deref(d)) | ||
println("Delay Value : " deref(d)) | ||
println("Promise Value : " deref(p)) | ||
println("Finished!") | ||
|
||
println("Future With Channels") | ||
println(async.<!!(c)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
local f = thread.future(function() | ||
println(str("Hello from " thread.id() "!")) | ||
print("Waiting") | ||
for i in range(5) do | ||
thread.sleep(500) | ||
print(".") | ||
end | ||
println("Done") | ||
end) | ||
|
||
println("Started!") | ||
deref(f) | ||
println("Finished!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(ns eden.stdlib.async | ||
(:require | ||
[eden.def :refer [set-var!]] | ||
[clojure.core.async :as async])) | ||
|
||
|
||
(def async-ns | ||
{:<!! async/<!! | ||
:>!! async/>!! | ||
:admix async/admix | ||
:alts!! async/alts!! | ||
:buffer async/buffer | ||
:chan async/chan | ||
:close! async/close! | ||
:dropping-buffer async/dropping-buffer | ||
:into async/into | ||
:map async/map | ||
:merge async/merge | ||
:mix async/mix | ||
:mult async/mult | ||
:offer! async/offer! | ||
:onto-chan async/onto-chan | ||
:pipe async/pipe | ||
:pipeline async/pipeline | ||
:pipeline-blocking async/pipeline-blocking | ||
:pipeline-async async/pipeline-async | ||
:poll! async/poll! | ||
:promise-chan async/promise-chan | ||
:pub async/pub | ||
:put! async/put! | ||
:put!! async/>!! | ||
:reduce async/reduce | ||
:sliding-buffer async/sliding-buffer | ||
:solo-mode async/solo-mode | ||
:split async/split | ||
:sub async/sub | ||
:take async/take | ||
:take! async/take! | ||
:take!! async/<!! | ||
:tap async/tap | ||
:timeout async/timeout | ||
:to-chan async/to-chan | ||
:toggle async/toggle | ||
:transduce async/transduce | ||
:unblocking-buffer? async/unblocking-buffer? | ||
:unmix async/unmix | ||
:unmix-all async/unmix-all | ||
:unsub async/unsub | ||
:unsub-all async/unsub-all | ||
:untap async/untap | ||
:untap-all async/untap-all}) | ||
|
||
|
||
(defn import-stdlib-async | ||
[eden] | ||
(-> eden | ||
(set-var! 'async async-ns))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns eden.stdlib.promise | ||
(:require | ||
[eden.def :refer [set-var!]])) | ||
|
||
|
||
(def promise-ns | ||
{:new promise | ||
:deliver deliver | ||
:realized? realized?}) | ||
|
||
|
||
(defn import-stdlib-promise | ||
[eden] | ||
(-> eden | ||
(set-var! 'promise promise-ns))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns eden.stdlib.thread | ||
(:require | ||
[eden.def :refer [set-var!]])) | ||
|
||
|
||
(defn future-wrap [f & args] | ||
(future (apply f args))) | ||
|
||
|
||
(defn delay-wrap [f & args] | ||
(delay (apply f args))) | ||
|
||
|
||
(def thread | ||
{:future future-wrap | ||
:delay delay-wrap | ||
:delay? delay? | ||
:realized? realized? | ||
:id #(.getId (Thread/currentThread)) | ||
:name #(.getName (Thread/currentThread)) | ||
:state #(.getState (Thread/currentThread)) | ||
:current #(Thread/currentThread) | ||
:sleep #(Thread/sleep %)}) | ||
|
||
|
||
(defn import-stdlib-thread | ||
[eden] | ||
(-> eden | ||
(set-var! 'thread thread))) |