Skip to content

Commit a6eea95

Browse files
author
KDr2
committed
add function CTask as a shortcut
1 parent aed5d14 commit a6eea95

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function f_ct()
2020
end
2121
end
2222

23-
t = Task(f_ct) |> enable_stack_copying
23+
t = CTask(f_ct)
24+
# or t = Task(f_ct) |> enable_stack_copying
2425

2526
consume(t) == 0
2627
consume(t) == 1
@@ -40,7 +41,9 @@ function f_ct2()
4041
end
4142
end
4243

43-
t = Task(f_ct2) |> enable_stack_copying
44+
t = CTask(f_ct2)
45+
# or t = Task(f_ct2) |> enable_stack_copying
46+
4447

4548
consume(t) == 0
4649
consume(t) == 1

src/Libtask.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Libtask
22

3-
export enable_stack_copying, consume, produce, TArray, get, tzeros, tfill, TRef
3+
export enable_stack_copying, CTask, consume, produce, TArray, get, tzeros, tfill, TRef
44

55
include("../deps/deps.jl"); check_deps();
66
include("taskcopy.jl")

src/taskcopy.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function enable_stack_copying(t::Task)
2222
return ccall((:jl_enable_stack_copying, libtask), Any, (Any,), t)::Task
2323
end
2424

25+
CTask(func) = Task(func) |> enable_stack_copying
26+
2527
function Base.copy(t::Task)
2628
t.state != :runnable && t.state != :done &&
2729
error("Only runnable or finished tasks can be copied.")

test/clonetask.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function f_ct2()
3232
end
3333
end
3434

35-
t = Task(f_ct2) |> enable_stack_copying
35+
t = CTask(f_ct2)
3636

3737
@test consume(t) == 0
3838
@test consume(t) == 1

0 commit comments

Comments
 (0)