github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/converter/testdata/autoexit_recvop.golden (about)

     1  package lgo_exec
     2  
     3  import pkg1 "lgo/pkg1"
     4  import pkg2 "github.com/yunabe/lgo/core"
     5  import pkg0 "lgo/pkg0"
     6  func f(ch chan int) int {
     7  	pkg2.ExitIfCtxDone()
     8  	return recvChan(ch)
     9  }
    10  func g(ch <-chan int) int {
    11  	pkg2.ExitIfCtxDone()
    12  	return recvChan0(ch)
    13  }
    14  func h(ch <-chan int) int {
    15  	pkg2.ExitIfCtxDone()
    16  	if i, ok := recvChan1(ch); ok {
    17  		return i
    18  	}
    19  	return -1
    20  }
    21  type Person struct {
    22  	name string
    23  	Age  int
    24  }
    25  func i() {
    26  	pkg2.ExitIfCtxDone()
    27  	ch := make(chan Person)
    28  	pkg2.ExitIfCtxDone()
    29  	recvChan2(ch)
    30  }
    31  func j() {
    32  	pkg2.ExitIfCtxDone()
    33  	recvChan3(pkg1.
    34  		getCh())
    35  }
    36  func k() {
    37  	pkg2.ExitIfCtxDone()
    38  	ch := make(chan struct {
    39  		name string
    40  		age  int
    41  	})
    42  	pkg2.ExitIfCtxDone()
    43  	recvChan4(ch)
    44  }
    45  func recvChan(c chan int) (x int) {
    46  	pkg2.ExitIfCtxDone()
    47  	select {
    48  	case x = <-c:
    49  		return
    50  	case <-pkg2.GetExecContext().Done():
    51  		panic(pkg2.Bailout)
    52  	}
    53  }
    54  func recvChan0(c <-chan int) (x int) {
    55  	pkg2.ExitIfCtxDone()
    56  	select {
    57  	case x = <-c:
    58  		return
    59  	case <-pkg2.GetExecContext().Done():
    60  		panic(pkg2.Bailout)
    61  	}
    62  }
    63  func recvChan1(c <-chan int) (x int, ok bool) {
    64  	pkg2.ExitIfCtxDone()
    65  	select {
    66  	case x, ok = <-c:
    67  		return
    68  	case <-pkg2.GetExecContext().Done():
    69  		panic(pkg2.Bailout)
    70  	}
    71  }
    72  func recvChan2(c chan Person) (x Person) {
    73  	pkg2.ExitIfCtxDone()
    74  	select {
    75  	case x = <-c:
    76  		return
    77  	case <-pkg2.GetExecContext().Done():
    78  		panic(pkg2.Bailout)
    79  	}
    80  }
    81  func recvChan3(c chan pkg0.person) (x pkg0.
    82  	person) {
    83  	pkg2.ExitIfCtxDone()
    84  	select {
    85  	case x = <-c:
    86  		return
    87  	case <-pkg2.GetExecContext().Done():
    88  		panic(pkg2.Bailout)
    89  	}
    90  }
    91  func recvChan4(c chan struct {
    92  	name string
    93  	age  int
    94  }) (x struct {
    95  	name string
    96  	age  int
    97  }) {
    98  	pkg2.ExitIfCtxDone()
    99  	select {
   100  	case x = <-c:
   101  		return
   102  	case <-pkg2.GetExecContext().Done():
   103  		panic(pkg2.Bailout)
   104  	}
   105  }