-
Notifications
You must be signed in to change notification settings - Fork 19
/
file.jl
38 lines (28 loc) · 928 Bytes
/
file.jl
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
32
33
34
35
36
37
38
export SyncFileObservable, file
import Base: ==
import Base: show
"""
SyncFileObservable(path::String)
File observable, which synchronously emits content of the file line by line as a `String` objects on subscription.
See also: [`file`](@ref), [`Subscribable`](@ref)
"""
struct SyncFileObservable <: Subscribable{String}
path :: String
end
function on_subscribe!(observable::SyncFileObservable, actor)
f = open(observable.path, "r")
for line in eachline(f)
next!(actor, line)
end
complete!(actor)
close(f)
return voidTeardown
end
"""
file(path::String)
Creation operator for the `SyncFileObservable` with a given path.
See also: [`SyncFileObservable`](@ref)
"""
file(path::String) = SyncFileObservable(path)
Base.:(==)(f1::SyncFileObservable, f2::SyncFileObservable) = f1.path == f2.path
Base.show(io::IO, observable::SyncFileObservable) = print(io, "SyncFileObservable()")