# Get task id of \`@asyncmap\`

**URL:** <https://discourse.julialang.org/t/get-task-id-of-asyncmap/30396>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 28, 2019, 8:51am UTC](https://discourse.julialang.org/t/get-task-id-of-asyncmap/30396 "2019-10-28T08:51:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![innerlee](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@innerlee](https://discourse.julialang.org/u/innerlee)\
**Post date:** [October 28, 2019, 8:51am UTC](https://discourse.julialang.org/t/get-task-id-of-asyncmap/30396/1 "2019-10-28T08:51:02Z")

</div>

How to get the task id in a `asyncmap`, similar to `myid()` in `pmap`?

Something like

```julia
asyncmap(_->myasyncid(), 1:10)

```

I want to use the id to balance workload on GPUs.

---

<div class="post-metadata">

**Author:** ![innerlee](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@innerlee](https://discourse.julialang.org/u/innerlee)\
**Post date:** [October 28, 2019, 9:33am UTC](https://discourse.julialang.org/t/get-task-id-of-asyncmap/30396/2 "2019-10-28T09:33:18Z")

</div>

Okay, workaround:

```julia
n = 0
gpumap = Dict()
asyncmap(1:32; ntasks=16) do file
    # get gpu id
    if haskey(gpumap, objectid(current_task()))
        GPU = gpumap[objectid(current_task())]
    else
        global n
        GPU = n % 8
        n += 1
        gpumap[objectid(current_task())] = GPU
    end
    println(GPU)
end

```

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [October 28, 2019, 7:07pm UTC](https://discourse.julialang.org/t/get-task-id-of-asyncmap/30396/3 "2019-10-28T19:07:00Z")

</div>

Seems like you should just be keying the Dict off of the `Task` itself (e.g. `current_task()`), rather than converting to a (theoretically non-unique) integer first?
