Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter committed Jan 31, 2024
1 parent a502db8 commit 05582dc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ StableTasks is a simple package with one main API `StableTasks.@spawn` (not expo
It works like `Threads.@spawn`, except it is *type stable* to `fetch` from.

``` julia
julia> Core.Compiler.return_type(() -> fetch(StableTasks.@spawn 1 + 1), Tuple{})
Int64
julia> using StableTasks, Test

julia> @inferred fetch(StableTasks.@spawn 1 + 1)
2
```
versus

``` julia
julia> Core.Compiler.return_type(() -> fetch(Threads.@spawn 1 + 1), Tuple{})
Any
julia> @inferred fetch(Threads.@spawn 1 + 1)
ERROR: return type Int64 does not match inferred return type Any
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] top-level scope
@ REPL[3]:1
```

The package also provides `StableTasks.@spawnat` (not exported), which is similar to `StableTasks.@spawn` but creates a *sticky* task (it won't migrate) on a specific thread.

```julia
julia> t = StableTasks.@spawnat 4 Threads.threadid();

julia> fetch(t)
julia> @inferred fetch(t)
4
```

0 comments on commit 05582dc

Please sign in to comment.