FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pixie/pixie/async.pxi at add-sorting · pixie-lang/pixie · GitHub
pixie-lang
/
pixie
Public
Notifications
You must be signed in to change notification settings
Fork
127
Star
2.4k
Code
Issues
46
Pull requests
9
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pixie
/
pixie
/
async.pxi
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (27 loc) · 765 Bytes
Breadcrumbs
pixie
/
pixie
/
async.pxi
Copy path
File metadata and controls
31 lines (27 loc) · 765 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns pixie.async
(:require [pixie.stacklets :
as
st]))
(deftype Promise [val pending
-
callbacks delivered?]
IDeref
(
-
deref [
self
]
(
if
delivered?
val
(do
(st
/
call
-
cc (fn [k]
(swap! pending
-
callbacks conj
(fn [v]
(st
/-
run
-
later (partial st
/
run
-
and
-
process k v)))))))))
IFn
(
-
invoke [
self
v]
(
assert
(
not
delivered?)
"
Can only deliver a promise once
"
)
(
set
-
field!
self
:val v)
(
set
-
field!
self
:delivered? true)
(doseq [f @pending
-
callbacks]
(f v))
(reset! pending
-
callbacks nil)
nil))
(defn promise []
(
-
>
Promise nil (atom []) false))
(defmacro future [
&
body]
`(let [p
#
(promise)]
(st
/
spawn (p
#
(do ~@body)))
p
#
))
Back
|
FazBrowse Home
|
New Git URL