> 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 <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/749338f8-ab6b-4849-a440-052a96686e95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to