Vector{Task}() and Vector{Task}

Hello everyone!
What is the difference between Vector{Task}() and Vector{Task}? The code below does not work with Vector{Task}, only with Vector{Task}(). Is there a better way to write this code?

Julia Version 1.7.3

function test_async()
	function test(s,i)
		sleep(i^2)
		open("test_async-$i", "w") do io
			println(io, "$s$i")
		end
	end
	v = Vector{Task}() # < --- --- ---
	for i=1:3
		println("task $i")
		v = vcat(v, @async test("Julia language -- $i.", i))
	end
	wait.(v)
	println("test_async()")
end

test_async()

the first is the type. the second is an instance of the type.

1 Like

Do you know why I need to use Vector{Task}() and can’t use Vector{Task}?

You could also use Task[]

julia> typeof(Vector{Task})
DataType

julia> typeof(Vector{Task}())
Vector{Task} (alias for Array{Task, 1})

Also, I think v = vcat(v, x) should be simply push!(v, x).

2 Likes