Created
September 3, 2012 10:02
-
-
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')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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