2017-10-21 113 views
1

我有一个管道,它看起来像Task.async_stream |> Stream.drop_while中是否有任何顺序?

digits 
|> Task.async_stream(__MODULE__, :filter, [s, values], timeout: :infinity) 
|> Stream.drop_while(fn {_, k} -> k == :contradiction or k == [] end) 
|> Stream.take(1) 

有此定义的任何命令?或者只是返回不满足条件的第一个filter的结果将返回?

回答

1

Task.async_streamhas an option for this:ordered: true | false。如果设置为true,则结果将与输入列表的顺序相同。如果它是错误的,结果将按任务完成的顺序排列。该选项的值默认为true,因此在您的代码中,结果将与输入列表的顺序相同。

iex(1)> [5, 4, 3, 2, 1] |> Task.async_stream(fn x -> :timer.sleep(x * 100); x end) |> Enum.to_list 
[ok: 5, ok: 4, ok: 3, ok: 2, ok: 1] 
iex(2)> [5, 4, 3, 2, 1] |> Task.async_stream(fn x -> :timer.sleep(x * 100); x end, ordered: false) |> Enum.to_list 
[ok: 1, ok: 2, ok: 3, ok: 4, ok: 5] 
相关问题