It seems that just casting the Token (future) as "shared" to get
it across the thread boundary works. From inside my thread:
receive(
(shared(Token) tok) {
int res = do_something();
(cast(Token)tok).set_result(res);
...
And then in the method which is exposed to the user:
Token start_something() {
auto tok = new Token();
send(tid, cast(shared) tok);
return tok;
}
As I showed, the "Token" class is carefully crafted with locks
and all to have an instance be shared across threads. But will
this casting back and forth to "shared" do the right thing? Each
thread now has a non-shared reference to the object.