import "golang.org/x/exp/old/netchan"
Package netchan implements type-safe networked channels: it allows the two ends of a channel to appear on different computers connected by a network. It does this by transporting data sent to a channel on one machine so it can be recovered by a receive of a channel of the same type on the other.
An exporter publishes a set of channels by name. An importer connects to the exporting machine and imports the channels by name. After importing the channels, the two machines can use the channels in the usual way.
Networked channels are not synchronized; they always behave as if they are buffered channels of at least one element.
The direction of a connection from the client's perspective.
type Exporter struct {
// contains filtered or unexported fields
}
An Exporter allows a set of channels to be published on a single network port. A single machine may have multiple Exporters but they must use different ports.
NewExporter creates a new Exporter that exports a set of channels.
Drain waits until all messages sent from this exporter/importer, including those not yet sent to any client and possibly including those sent while Drain was executing, have been received by the importer. In short, it waits until all the exporter's messages have been received by a client. If the timeout is positive and Drain takes longer than that to complete, an error is returned.
Export exports a channel of a given type and specified direction. The channel to be exported is provided in the call and may be of arbitrary channel type. Despite the literal signature, the effective signature is
Export(name string, chT chan T, dir Dir)
Hangup disassociates the named channel from the Exporter and closes the channel. Messages in flight for the channel may be dropped.
ListenAndServe exports the exporter's channels through the given network and local address defined as in net.Listen.
Serve waits for incoming connections on the listener and serves the Exporter's channels on each. It blocks until the listener is closed.
func (exp *Exporter) ServeConn(conn io.ReadWriter)
ServeConn exports the Exporter's channels on conn. It blocks until the connection is terminated.
Sync waits until all clients of the exporter have received the messages that were sent at the time Sync was invoked. Unlike Drain, it does not wait for messages sent while it is running or messages that have not been dispatched to any client. If the timeout is positive and Sync takes longer than that to complete, an error is returned.
type Importer struct {
// contains filtered or unexported fields
}
An Importer allows a set of channels to be imported from a single remote machine/network port. A machine may have multiple importers, even from the same machine/network port.
Import imports a set of channels from the given network and address.
func NewImporter(conn io.ReadWriter) *Importer
NewImporter creates a new Importer object to import a set of channels from the given connection. The Exporter must be available and serving when the Importer is created.
Drain waits until all messages sent from this exporter/importer, including those not yet sent to any server and possibly including those sent while Drain was executing, have been received by the exporter. In short, it waits until all the importer's messages have been received. If the timeout (measured in nanoseconds) is positive and Drain takes longer than that to complete, an error is returned.
Errors returns a channel from which transmission and protocol errors can be read. Clients of the importer are not required to read the error channel for correct execution. However, if too many errors occur without being read from the error channel, the importer will shut down.
Hangup disassociates the named channel from the Importer and closes the channel. Messages in flight for the channel may be dropped.
Import imports a channel of the given type, size and specified direction. It is equivalent to ImportNValues with a count of -1, meaning unbounded.
ImportNValues imports a channel of the given type and specified direction and then receives or transmits up to n values on that channel. A value of n==-1 implies an unbounded number of values. The channel will have buffer space for size values, or 1 value if size < 1. The channel to be bound to the remote site's channel is provided in the call and may be of arbitrary channel type. Despite the literal signature, the effective signature is
ImportNValues(name string, chT chan T, dir Dir, size, n int) error
Example usage:
imp, err := NewImporter("tcp", "netchanserver.mydomain.com:1234") if err != nil { log.Fatal(err) } ch := make(chan myType) err = imp.ImportNValues("name", ch, Recv, 1, 1) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", <-ch)
Package netchan imports 9 packages (graph). Updated a day ago. Refresh now. Tools for package owners.