Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
defmodule MyReceive do
defmacro my_receive(do: clauses) do
extra = quote do
other -> IO.puts "got #{inspect other}"
end
quote do
receive do: unquote(clauses ++ extra)
end
end
diff --git a/lib/gen_event.ex b/lib/gen_event.ex
index bc2a34f..07ca53f 100644
--- a/lib/gen_event.ex
+++ b/lib/gen_event.ex
@@ -468,8 +468,12 @@ defimpl Enumerable, for: GenEvent do
send mon_pid, { :UP, mon_ref, self() }
receive do
- { :UP, ^mon_ref, manager_pid } -> { mon_ref, mon_pid, manager_pid }
- { :DOWN, ^mon_ref, _, _, reason } -> exit(reason)
defmodule Mix.TasksServer do
@moduledoc false
use GenServer.Behaviour
def start_link() do
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, :ok, [])
end
def clear_tasks() do
call :clear_tasks
diff --git a/lib/task/sup.ex b/lib/task/sup.ex
index 3070aa2..4cc4968 100644
--- a/lib/task/sup.ex
+++ b/lib/task/sup.ex
@@ -66,10 +66,14 @@ defmodule Task.Sup do
"""
@spec async(Supervisor.supervisor, module, atom, [term]) :: Task.t
def async(supervisor, module, fun, args) do
- { :ok, pid } = Supervisor.start_child(supervisor, [self(), { module, fun, args }])
+ lock = make_ref()

Before

A map pattern will match any map that has the given keys and values. For example, %{"hello" => world} will match any map that has the key "hello". An empty map therefore matches all maps.

After

A map pattern will match any map that has all the keys specified in the pattern. The values for the matching keys must also match. For example, %{"hello" => world} will match any map that has the key "hello" and assign the value to world, while %{"hello" => "world"} will match any map that has the key "hello"with value equals to"world". An empty map pattern (%{}`) will match all maps.

defmodule Poolboy.Mixfile do
use Mix.Project
@version File.read!("VERSION") |> String.strip
def project do
[app: :poolboy,
version: @version,
description: "A hunky Erlang worker pool factory",
package: package]
diff --git a/lib/kernel/src/user_drv.erl b/lib/kernel/src/user_drv.erl
index 7b4ffb0..745fe46 100644
--- a/lib/kernel/src/user_drv.erl
+++ b/lib/kernel/src/user_drv.erl
@@ -172,17 +172,17 @@ server_loop(Iport, Oport, Curr, User, Gr) ->
{Iport,eof} ->
Curr ! {self(),eof},
server_loop(Iport, Oport, Curr, User, Gr);
- {User,Req} -> % never block from user!
- io_request(Req, Iport, Oport),
defmodule Foo do
@menu [foo: 1, bar: 3, baz: 2]
@filtered_menu @menu |> Enum.filter(...)
def filtered_menu do
@filtered_menu
end
end
defmodule FibAgent do
def start_link do
cache = Enum.into([{0, 0}, {1, 1}], HashDict.new)
Agent.start_link(fn -> cache end)
end
def fib(pid, n) when n >= 0 do
Agent.get_and_update(pid, &do_fib(&1, n))
end
# config/config.exs
use Mix.Config
config :lager,
handlers: [
lager_console_backend: [:info, {:lager_default_formatter, [:time, ' [', :severity, '] ', :message, '\n']}]
],
crash_log: :undefined,
error_logger_hwm: 150