Skip to content

Commit 4e1e5df

Browse files
committed
Some docs
1 parent a63660e commit 4e1e5df

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

docs/make.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
using Documenter, Libtask
22

3-
makedocs(; sitename="Libtask")
3+
DocMeta.setdocmeta!(
4+
Libtask,
5+
:DocTestSetup,
6+
quote
7+
using Libtask
8+
end;
9+
recursive=true,
10+
)
11+
12+
makedocs(;
13+
sitename="Libtask", doctest=true, pages=["index.md", "internals.md"], modules=[Libtask]
14+
)
15+
16+
deploydocs(; repo="github.com/TuringLang/Libtask.jl.git", push_preview=true)

docs/src/internals.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Internals
2+
3+
```@docs; canonical=true
4+
Libtask.produce_value
5+
Libtask.is_produce_stmt
6+
Libtask.might_produce
7+
```

src/copyable_task.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,78 @@ end
4545
4646
Construct a `TapedTask` with the specified `dynamic_scope`, for function `f` and positional
4747
arguments `args`.
48+
49+
# Extended Help
50+
51+
There are three central features of a `TapedTask`, which we demonstrate via three examples.
52+
53+
## Resumption
54+
55+
```jldoctest tt
56+
julia> function f()
57+
for t in 1:2
58+
produce(t)
59+
t += 1
60+
end
61+
return nothing
62+
end
63+
f (generic function with 1 method)
64+
```
65+
66+
```jldoctest tt
67+
julia> t = TapedTask(nothing, f);
68+
69+
julia> consume(t)
70+
1
71+
```
72+
73+
```jldoctest tt
74+
julia> consume(t)
75+
2
76+
77+
julia> consume(t)
78+
79+
```
80+
81+
## Copying
82+
83+
```jldoctest tt
84+
julia> t2 = TapedTask(nothing, f);
85+
86+
julia> consume(t2)
87+
1
88+
```
89+
90+
```jldoctest tt
91+
julia> t3 = copy(t2);
92+
93+
julia> consume(t3)
94+
2
95+
96+
julia> consume(t2)
97+
2
98+
```
99+
100+
## Scoped Values
101+
102+
```jldoctest
103+
julia> function f()
104+
produce(get_dynamic_scope())
105+
produce(get_dynamic_scope())
106+
return nothing
107+
end
108+
f (generic function with 1 method)
109+
110+
julia> t = TapedTask(1, f);
111+
112+
julia> consume(t)
113+
1
114+
115+
julia> set_dynamic_scope!(t, 2)
116+
117+
julia> consume(t)
118+
2
119+
```
48120
"""
49121
function TapedTask(dynamic_scope::Any, fargs...)
50122
mc, count_ref = build_callable(Base.code_ircode_by_type(typeof(fargs))[1][1])

0 commit comments

Comments
 (0)