# Vector{Task}() and Vector{Task}

**URL:** https://discourse.julialang.org/t/vector-task-and-vector-task/84500
**Category:** General Usage
**Created:** [July 20, 2022, 12:52am UTC](https://discourse.julialang.org/t/vector-task-and-vector-task/84500 "2022-07-20T00:52:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)
#### Post date: [July 20, 2022, 12:52am UTC](https://discourse.julialang.org/t/vector-task-and-vector-task/84500/1 "2022-07-20T00:52:32Z")

</div>

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

```julia
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()

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [July 20, 2022, 12:54am UTC](https://discourse.julialang.org/t/vector-task-and-vector-task/84500/2 "2022-07-20T00:54:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)
#### Post date: [July 20, 2022, 2:29am UTC](https://discourse.julialang.org/t/vector-task-and-vector-task/84500/3 "2022-07-20T02:29:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [July 20, 2022, 2:44am UTC](https://discourse.julialang.org/t/vector-task-and-vector-task/84500/4 "2022-07-20T02:44:02Z")

</div>

You could also use `Task[]`

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [July 20, 2022, 3:54am UTC](https://discourse.julialang.org/t/vector-task-and-vector-task/84500/5 "2022-07-20T03:54:28Z")

</div>

```julia
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)`.
