Example #1
0
File: main.go Project: qrush/go
func importReceive(imp *netchan.Importer) {
	ch := make(chan value)
	imp.ImportNValues("exportedSend", ch, netchan.Recv, new(value), count)
	for i := 0; i < count; i++ {
		v := <-ch
		fmt.Printf("%v\n", v)
		if v.i != 23+i || v.s != "hello" {
			fmt.Printf("importReceive: bad value: expected %d, hello; got %+v", 23+i, v)
		}
	}
}
Example #2
0
func importChan(imp *netchan.Importer, name string, done chan os.Error) {
	ch := make(chan string)
	err := imp.Import(name, ch, netchan.Recv)
	if err != nil {
		log.Println("Error during channel import: ", err)
		done <- err
	}
	for line := <-ch; !closed(ch); line = <-ch {
		log.Print(line)
	}
	done <- os.NewError("No moar inputs")
}
Example #3
0
// Dial makes a connection to the named netchan service,
// which must have been previously exported with a call to Listen.
func Dial(imp *netchan.Importer, service string) (net.Conn, error) {
	cnames := make(chan string)
	err := imp.ImportNValues(service, cnames, netchan.Recv, 1, 1)
	if err != nil {
		return nil, err
	}
	clientName := <-cnames
	reqname := clientName + ".req"
	replyname := clientName + ".reply"
	req := make(chan []byte)
	err = imp.Import(reqname, req, netchan.Send, 200)
	if err != nil {
		return nil, err
	}
	reply := make(chan []byte)
	err = imp.Import(replyname, reply, netchan.Recv, 200)
	if err != nil {
		return nil, err
	}
	req <- []byte(initMessage)
	return &Conn{
		R:          reply,
		W:          req,
		chanReader: &chanReader{c: reply},
		chanWriter: &chanWriter{c: req},
		clientName: clientName,
		localAddr:  netchanAddr("unknown"),
		remoteAddr: netchanAddr(service),
		nc:         imp,
	}, nil
}