Created
March 15, 2012 20:24
-
-
Save Licenser/2046667 to your computer and use it in GitHub Desktop.
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
process(Data) -> | |
gen_server:cast(?SERVER, {process, Data}); | |
... | |
handle_cast({process, Data}, {}) -> | |
do_some_funky_stuff(Data), | |
reader:pop(self); | |
{ok, {}} |
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
pop(Reader) -> | |
gen_server:cast(?SERVER, {pop, Reader}); | |
push(Data) -> | |
gen_server:cast(?SERVER, {push, Data}); | |
... | |
handle_cast({pop, Reader}, {[], Readers}) -> | |
{ok, {[], [Reader | Readers]}}; | |
handle_cast({pop, Reader}, {[Data | R], []}) -> | |
consumer:process(Reader, Data), | |
{ok, {R, []}}; | |
handle_cast({pop, Reader}, {[Data | R], [First | Rdrs]}) -> | |
consumer:process(First, Data), | |
{ok, {R, [Reader | Rdrs]}}; | |
handle_cast({push, Data}, {Dates, []}) -> | |
{ok, {[Data| Dates], []}}; | |
handle_cast({push, Data}, {[], [First | Rdrs]}) -> | |
consumer:process(First, Data), | |
{ok, {[], Rdrs}}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment