Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typed Tasks in Julia

Tags:

julia

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?

like image 629
lyomi Avatar asked Nov 11 '22 01:11

lyomi


1 Answers

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.

like image 89
IainDunning Avatar answered Dec 07 '22 07:12

IainDunning