# Does Ray remote functions return in correct order?

**URL:** https://discuss.ray.io/t/does-ray-remote-functions-return-in-correct-order/9482
**Category:** Ray Core
**Created:** [February 23, 2023, 9:24pm UTC](https://discuss.ray.io/t/does-ray-remote-functions-return-in-correct-order/9482 "2023-02-23T21:24:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![xzf0kgb0bqr.cev2RWU](https://avatars.discourse-cdn.com/v4/letter/x/65b543/32.png) [@xzf0kgb0bqr.cev2RWU](https://discuss.ray.io/u/xzf0kgb0bqr.cev2RWU)
#### Post date: [February 23, 2023, 9:24pm UTC](https://discuss.ray.io/t/does-ray-remote-functions-return-in-correct-order/9482/1 "2023-02-23T21:24:46Z")

</div>

- Medium: It contributes to significant difficulty to complete my task, but I can work around it.

_ **Main Question** _

Do ray remote functions output results in correct order?

If I call

`ray.get([do_some_work.remote(x) for x in range(2)]`

and `do_some_work(1)` finishes earlier than `do_some_work(0)`, will I get:

a) `[do_some_work(1), do_some_work(0)]`  
b) `[do_some_work(0), do_some_work(1)]`

I would like to get option (b), so if the answer is (a), is there a way to make enforce that I get option (b)?

_ **More details** _

Taking code from the Ray tutorial “Tips for first-time users”:

```auto
@ray.remote
def do_some_work(x):
    time.sleep(random.uniform(0, 4)) # Replace this with work you need to do.
    return x

data_list = ray.get([do_some_work.remote(x) for x in range(4)])

```

Since `do_some_work` takes a variable amount of time, will Ray know I want the results to be:

```auto
[do_some_work(0), do_some_work(1), do_some_work(2), do_some_work(2)]

```

or will it output in the order of whichever job finishes earlier?

---

<div class="post-metadata">

### Author: ![yic](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yic/32/437_2.png) [@yic](https://discuss.ray.io/u/yic)
#### Post date: [February 24, 2023, 2:38am UTC](https://discuss.ray.io/t/does-ray-remote-functions-return-in-correct-order/9482/2 "2023-02-24T02:38:56Z")

</div>

It’ll be the order you expect. Basically, a = f(b) and a will always be the result of f(b).

```auto
data_list == [do_some_work(0), do_some_work(1), do_some_work(2), do_some_work(2)]

```
