In many other languages one can make a generic asynchronous iterable type, like Observable<T>
in Rx variants, chan T
in Go.
Julia's coroutine abstraction Task
is a comparable construct which can pass objects between (lightweight) threads. Does Julia have a method to annotate the type of those objects?
I would like to make a function that accepts a Task
as its parameter and be able to express the type of objects that the task emits. For example, if Task
were a generic type, I would imagine:
function foo(socket::Task{String})
for word in socket
println(word)
end
end
More generally, is there an abstract type for objects that are iterable using for
(or other methods using start
/next
/done
) so that I can annotate in function signatures?
I don't believe there is such a thing at this time.
On your "more general" question, there isn't such a thing yet, but its something people want. Here is an issue with people discussing ideas and possibilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With