Skip to content

Instantly share code, notes, and snippets.

@sumerman
Created September 3, 2012 10:02
Show Gist options
  • Save sumerman/3608235 to your computer and use it in GitHub Desktop.
Save sumerman/3608235 to your computer and use it in GitHub Desktop.
Thoughts on safe Erlang PD usage to deal with short-living state (instead PTs like 'SeqBind')
-module(pdscope).
-export([pput/1, pget/0, pdscope/1, example/0]).
pput(X) ->
erlang:put(?MODULE, X).
pget() ->
erlang:get(?MODULE).
pdscope(Scope, F) ->
try
F()
after
erase(?MODULE)
end.
example() ->
pdscope(fun() ->
pput(cowboy_req:foobar(11,2,2)),
pput(cowboy_req:barban(pget(), 2,3)
end).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment