You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/index.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -394,3 +394,38 @@ Dagger.@spawn copyto!(C, X)
394
394
395
395
In contrast to the previous example, here, the tasks are executed without argument annotations. As a result, there is a possibility of the `copyto!` task being executed before the `sort!` task, leading to unexpected results in the output array `C`.
396
396
397
+
## Quickstart: Streaming
398
+
399
+
Dagger.jl provides a streaming API that allows you to process data in a streaming fashion, where data is processed as it becomes available, rather than waiting for the entire dataset to be loaded into memory.
400
+
401
+
For more details: [Streaming](@ref)
402
+
403
+
### Syntax
404
+
405
+
The `Dagger.spawn_streaming()` function is used to create a streaming region,
406
+
where tasks are executed continuously, processing data as it becomes available:
407
+
408
+
```julia
409
+
# Open a file to write to on this worker
410
+
f = Dagger.@mutableopen("output.txt", "w")
411
+
t = Dagger.spawn_streaming() do
412
+
# Generate random numbers continuously
413
+
val = Dagger.@spawnrand()
414
+
# Write each random number to a file
415
+
Dagger.@spawn (f, val) ->begin
416
+
if val <0.01
417
+
# Finish streaming when the random number is less than 0.01
418
+
Dagger.finish_stream()
419
+
end
420
+
println(f, val)
421
+
end
422
+
end
423
+
# Wait for all values to be generated and written
424
+
wait(t)
425
+
```
426
+
427
+
The above example demonstrates a streaming region that generates random numbers
428
+
continuously and writes each random number to a file. The streaming region is
429
+
terminated when a random number less than 0.01 is generated, which is done by
430
+
calling `Dagger.finish_stream()` (this terminates the current task, and will
431
+
also terminate all streaming tasks launched by `spawn_streaming`).
Cancels `task` at any point in its lifecycle, causing the scheduler to abandon
5
-
it. If `force` is `true`, the task will be interrupted with an
6
-
`InterruptException` (not recommended, this is unsafe). If `halt_sch` is
7
-
`true`, the scheduler will be halted after the task is cancelled (it will
8
-
restart automatically upon the next `@spawn`/`spawn` call).
53
+
it.
54
+
55
+
# Keyword arguments
56
+
- `force`: If `true`, the task will be interrupted with an `InterruptException` (not recommended, this is unsafe).
57
+
- `graceful`: If `true`, the task will be allowed to finish its current execution before being cancelled; otherwise, it will be cancelled as soon as possible.
58
+
- `halt_sch`: If `true`, the scheduler will be halted after the task is cancelled (it will restart automatically upon the next `@spawn`/`spawn` call).
9
59
10
60
As an example, the following code will cancel task `t` before it finishes
11
61
executing:
@@ -21,24 +71,24 @@ tasks which are waiting to run. Using `cancel!` is generally a much safer
21
71
alternative to Ctrl+C, as it cooperates with the scheduler and runtime and
0 commit comments