Live data from Hacker News

Futures in Go

blog.charmes.net

11–15 of 15 posts

Re: Futures in Go

#11
This error pops up for me:

    This site or app is sending too much traffic to   
    rawgit.com. Please contact its owner and ask them to use 
    cdn.rawgit.com instead, which has no traffic limit.

Re: Futures in Go

#12

This error pops up for me: This site or app is sending too much traffic to rawgit.com. Please contact its owner and ask them to use cdn.rawgit.com instead, which has no traffic limit.

It saddens me that this tool does not fail elegantly. It should deny access to the resource rather than mess with the browser.

Re: Futures in Go

#13
post #10
post #9

Earlier quoted context omitted.

I don't think I've ever heard it clearly explained why you rarely need futures in Go. (The blog article doesn't explain it either.) It seems to be because each goroutine has a single parent (which launched it), so there is typically a single reader for its return value.

I'm not sure that's the case. Erlang has public-addressable processes: you can pass a process's handle around, and then anything with that handle can direct messages to that process—including messages containing their own process handles, allowing for responses; built on top of this, there's a global service registry, allowing anything to direct messages to a given process. Despite this, Erlang still doesn't need fut…

I think that explains why languages like JavaScript will have many functions that return Promises and Go doesn't need that kind of API. Often in JavaScript, there will only be one reader for the result of a function call, but you'll use a Promise anyway since there are no threads.

But there are cases where you really want multiple readers. For example, on a cache miss, you want a single goroutine to do the work to fill the cache, but there may be multiple goroutines waiting on the result. In this case it might seem natural to model the cache internally as a map from keys to futures, even if it's not exposed?

Re: Futures in Go

#14
post #4

Futures are not necessary in Go, since they are a hack around not having the concurrency that Go supports natively. This is why the Go community never talks about "futures"... as in this example, they are a regression vs. the already-supported primitives, not progress. Channels are already a more general, more powerful, and most importantly, more composable version of the "futures" idea that is what most people consi…

Agreed. Passing around channels (they are values anyway) makes a lot of concurrency problems simpler.

Re: Futures in Go

#15
post #10
post #9

Earlier quoted context omitted.

I don't think I've ever heard it clearly explained why you rarely need futures in Go. (The blog article doesn't explain it either.) It seems to be because each goroutine has a single parent (which launched it), so there is typically a single reader for its return value.

I'm not sure that's the case. Erlang has public-addressable processes: you can pass a process's handle around, and then anything with that handle can direct messages to that process—including messages containing their own process handles, allowing for responses; built on top of this, there's a global service registry, allowing anything to direct messages to a given process. Despite this, Erlang still doesn't need fut…

Your actor-modelled example doesn't touch the idea behind promises, ie the background operations should return a result that is usable by the "main thread". In your example, that would be "result" being passed in some way to "more_random_other_work".

The way to do it would be closer to something like that:

    do_random_other_work();
    actor = spawn(function() {
      bfn_args = some_setup();
      result = blocking_fn(bfn_args);
      emit(result);
    });
    result = wait_for_result(actor)
    more_random_other_work(result);
Post reply on HN