Skip to content

Instantly share code, notes, and snippets.

@eholk
Created July 11, 2011 21:23
Show Gist options
  • Select an option

  • Save eholk/1076821 to your computer and use it in GitHub Desktop.

Select an option

Save eholk/1076821 to your computer and use it in GitHub Desktop.
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