An important thing to note is that in Elixir it's generally the caller of a 
function that determines whether they  want sync or async behaviour, not 
the callee. Generally speaking you simply write functions that take input 
and return output. If a given caller of that function wants that to happen 
async then it can use Task or some other construct for doing so. If another 
caller wants to do it sync then they just call the function.

Throughout all of this though all the processes are async with respect to 
one another already, and this is enforced by the VM and requires no special 
language handling.

On Tuesday, January 23, 2018 at 2:54:03 PM UTC-5, Pedro Medeiros wrote:
>
> Thanks for the response people.
>
> I knwon using tasks always is not the best way to go, but I do fell we can 
> make somehow a better abstraction for processes only with what the language 
> have.
>
> I’m gonna write something down later, thanks for the advice Wojtek.
>
> On Tue, Jan 23, 2018 at 2:38 PM Wojtek Mach <woj...@wojtekmach.pl 
> <javascript:>> wrote:
>
>> > Also another benefit is having a syntax more similar to other 
>> languages. This can make Elixir more welcoming for people from other 
>> communities such as python or javascript.
>>
>> Adding syntax and APIs that feel familiar is one way to potentially make 
>> it easy for people to learn Elixir. It doesn't seem like a scalable 
>> approach however because it'd likely result in bloat of the language and/or 
>> stdlib.
>>
>> Another way is to prepare learning materials, perhaps a blog post 
>> "Python/JavaScript async in Elixir", where functions like Task.async,await, 
>> Task.Supervisor.async_nolink, Task.async_stream and spawn are discussed.
>> One could even show that with macros we can implement "async" keyword 
>> pretty easily:
>>
>> defmodule DefAsync do
>>   defmacro defasync(call, do: block) do
>>     quote do
>>       def unquote(call) do
>>         Task.async(fn -> unquote(block) end)
>>       end
>>     end
>>   end
>> end
>>
>>
>> defmodule Foo do
>>   import DefAsync
>>
>>   defasync delayed_foo(value) do
>>     :timer.sleep(1_000)
>>     IO.inspect value
>>   end
>> end
>>
>>
>> Foo.delayed_foo(42) |> Task.await()
>>
>> W dniu wtorek, 23 stycznia 2018 16:01:06 UTC+1 użytkownik Pedro Medeiros 
>> napisał:
>>
>>> Hi,
>>>
>>> I'm writing this proposal based on what I've been doing with 
>>> Python/Javascript. A way ppl on those communities are doing asynchronous 
>>> call nowadays is by declaring an async function and if there is a need to 
>>> wait for its result calls the function await. Once we have the module Task 
>>> that is capable of handling mostly user cases about async/await feature on 
>>> those languages. I think we can add async to the function definition to 
>>> implement 
>>>
>>> defmodule Foo do
>>>   async def bar(x)    # code
>>>   endend
>>>
>>>
>>>
>>> And on the code by calling Foo.bar/1 we return a Task. And by calling 
>>> Task.async Foo.foo(1) the result can be returned.
>>>
>>> the main benefits on having an approach like that is basically code 
>>> readability when it is necessary to run a single function as a separate 
>>> process. today that can be done with something like that
>>>
>>> task = Task.async(fn ->
>>>   Foo.bar(:arg)end)Task.await(task)
>>>
>>>
>>> or
>>>
>>> task = Task.async(Foo, :bar, [:arg])Task.await(task)
>>>
>>>
>>> Also another benefit is having a syntax more similar to other languages. 
>>> This can make Elixir more welcoming for people from other communities such 
>>> as python or javascript.
>>> -- 
>>>
>> Pedro Medeiros
>>> ----------------------------------
>>> Cel: +55 (21) 9914-86898
>>>
>> Email: pedr...@gmail.com
>>>
>>
>>> Beautiful is better than ugly,
>>> Explicit is better than implicit,
>>> Simple is better than complex,
>>> Complex is better than complicated.
>>>
>>> The Zen of Python, by Tim Peters
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/749338f8-ab6b-4849-a440-052a96686e95%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/749338f8-ab6b-4849-a440-052a96686e95%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> -- 
> Pedro Henrique de Souza Medeiros
> ----------------------------------
> Cel: +55 (21) 9914-86898
> Email: pedr...@gmail.com <javascript:>
>
> Beautiful is better than ugly,
> Explicit is better than implicit,
> Simple is better than complex,
> Complex is better than complicated.
>
> The Zen of Python, by Tim Peters
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/d5540d39-645f-4f1c-b13d-7675bf305197%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to