Created
July 11, 2011 21:23
-
-
Save eholk/1076821 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| mod shared_cache { | |
| tag response[K, V] { | |
| not_found(K); | |
| found(K, V); | |
| } | |
| tag command[K, V] { | |
| put_item(K, V); | |
| get_item(K, chan[response[K,V]]); | |
| quit; | |
| } | |
| type proxy[K, V] = obj { | |
| }; | |
| fn cache_server[K, V] (chan[chan[command[K,V]]] c) { | |
| let port[command[K,V]] ctrl = port(); | |
| c <| chan(ctrl); | |
| while(true) { | |
| auto cmd; | |
| ctrl |> cmd; | |
| alt(cmd) { | |
| case(put_item(?key, ?val)) { | |
| fail | |
| } | |
| case(get_item(?key, ?out)) { | |
| fail | |
| } | |
| case(quit) { | |
| break; | |
| } | |
| } | |
| } | |
| log_err "Cache server exiting" | |
| } | |
| fn start_server[K, V]() -> chan[command[K,V]] { | |
| let port[chan[command[K, V]]] p = port(); | |
| // Uh oh... this exposes issues with the task lifetime system. | |
| spawn cache_server(chan(p)); | |
| auto c; | |
| p |> c; | |
| ret c; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment