github.com/btwiuse/jiri@v0.0.0-20191125065820-53353bcfef54/simplemr/example_test.go (about)

     1  // Copyright 2015 The Vanadium Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package simplemr_test
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/btwiuse/jiri/simplemr"
    11  )
    12  
    13  func ExampleMR() {
    14  	in, out := make(chan *simplemr.Record, 2), make(chan *simplemr.Record, 2)
    15  	mr := &simplemr.MR{}
    16  	identity := &simplemr.Identity{}
    17  	go mr.Run(in, out, identity, identity)
    18  	in <- &simplemr.Record{"1", []interface{}{"hello\n"}}
    19  	in <- &simplemr.Record{"2", []interface{}{"world\n"}}
    20  	close(in)
    21  	k := <-out
    22  	fmt.Printf("%s: %s", k.Key, k.Values[0].(string))
    23  	k = <-out
    24  	fmt.Printf("%s: %s", k.Key, k.Values[0].(string))
    25  	if err := mr.Error(); err != nil {
    26  		fmt.Printf("mr failed: %v", err)
    27  	}
    28  	// Output:
    29  	// 1: hello
    30  	// 2: world
    31  }