sago35 / ochan

Package ochan provides ordered chan.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Actions Status GoDoc Reference Go Report Card

Ochan

Package ochan provides ordered chan.

Usage

Package ochan supports generics.
Thus, it can work with any type by supplying chan T to NewOchan().
See ochan_test.go for an example of its use.

func ExampleOchan() {
	result := make(chan string, 100)
	o := NewOchan(result, 100)

	c1 := o.GetCh()
	c2 := o.GetCh()

	c1 <- "Hello c1"
	c2 <- "Hello c2"
	c1 <- "Bye c1"
	c2 <- "Bye c2"

	close(c1)
	close(c2)

	o.Wait()
	close(result)

	for s := range result {
		fmt.Println(s)
		// Output:
		// Hello c1
		// Bye c1
		// Hello c2
		// Bye c2
	}
}

Licence

MIT

About

Package ochan provides ordered chan.

License:MIT License


Languages

Language:Go 100.0%