News for hackers. Stuff that matters.
Re:The Beauty of Concurrency in Go by hornetblack on Sunday April 28, 2013 @06:49PM (#5623133)
Futures in C++11 are similar:

    int x = std::async([]()->int{
            return 100;
        });
    std::cout << x.wait() << std::endl:
Which isn't as nice as closure. Go could probably benfit from having a standard futures tool. I guess something along the lines of:

    type Future {
        Wait() interface{}
    }

    func newFuture(func interface{}, 
                args ...interface{}) Future
Re:The Beauty of Concurrency in Go by cerales on Sunday April 28, 2013 @09:23PM (#5623618)
Yep, futures can be done easily in Go with a goroutine that sends a single value on a channel, but: 1) you can't dereference the value multiple times in Go, so you have to manage saving it yourself, and 2) there's no syntactic sugar. Pity.
Re:The Beauty of Concurrency in Go by hornetblack on Sunday April 28, 2013 @09:29PM (#5623633)
You could save the future in the Future implementation

    type future struct {
        completed   bool
        result      interface{}
        ch        <-chan interface{}
    }
Edit: Or just check if the channel is closed

    func (f *future) Wait() interface{} {
        v, ok := <- ch
        if ok { f.result = v; return v }
        else  { return f.result }
    }
Re:The Beauty of Concurrency in Go by hornetblack on Sunday April 28, 2013 @11:08PM (#5623870)
I got this wrong. std::async should not return an int. It's should be std::future