Hacker News new | past | comments | ask | show | jobs | submit login

I would love to see a small example/snippet illustrating how I'd use this.



Here's how you would implement basic RPC-style request/response.

On the client:

    var ch libchan.Sender

    // Send a message, indicate that we want a return channel to be automatically created
    ret1, err := ch.Send(&libchan.Message{Data: []byte("request 1!"), Ret: libchan.RetPipe})

    // Send another message on the same channel
    ret2, err := ch.Send(&libchan.Message{Data: []byte("request 2!"), Ret: libchan.RetPipe})

    // Wait for an answer from the first request. Set flags to zero
    // to indicate we don't want a nested return channel
    msg, err := ret1.Receive(0)
    fmt.Printf("Received answer: %s\n", msg.Data)
On the server:

    var ch libchan.Receiver

    // Wait for messages in a loop
    // Set the return channel flag,
    // to indicate we want to receive nested channels (if any).
    // Note: we don't send a nested return channel, but we could.
    for {
        msg, err := ch.Receive(libchan.Ret)
        msg.Ret.Send(&libchan.Message{Data: []byte("this is an utterly useless response")})
    }


Here are Solomon's slides on the topic.

http://www.slideshare.net/shykes/docker-the-road-ahead


I came here to say the same thing. Neither the README nor the examples folder had a very short, basic example. Thanks for the answer (below/above).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: