Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save binarytemple/cbd2d0e45087a3f6be34 to your computer and use it in GitHub Desktop.

Select an option

Save binarytemple/cbd2d0e45087a3f6be34 to your computer and use it in GitHub Desktop.

Trying to create...

A function which takes a function as it's argument, spawning it in new process, waiting for it's result, then returning the result.

I can't get the syntax right.

2> FooAsync =  fun(Infun) -> Parent = self(), spawn( fun() -> X = Infun(), Parent ! X  end ) , ok   end .
#Fun<erl_eval.6.82930912>
3> FooAsync =  fun(Infun) -> Parent = self(), spawn( fun() -> X = "foo" , Parent ! X  end ) , receive Y -> Y  end .
* 2: syntax error before: '.'
3> FooAsync =  fun(Infun) -> Parent = self(), spawn( fun() -> X = "foo" , Parent ! X  end ) , Res = receive Y -> Y, Res  end .
* 2: syntax error before: '.'
5> fun(Infun) -> Parent = self(), spawn( fun() -> X = Infun(), Parent ! X  end ) , ok   end .
#Fun<erl_eval.6.82930912>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment