File: main.go

package info (click to toggle)
golang-gitlab-jonas.jasas-condchan 0.0~git20190210.36637ad-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 88 kB
  • sloc: makefile: 3
file content (26 lines) | stat: -rw-r--r-- 529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import (
	"fmt"
	"gitlab.com/jonas.jasas/condchan"
	"sync"
	"time"
)

func main() {
	fmt.Println("Timeout example")
	cc := condchan.New(&sync.Mutex{})
	timeoutChan := time.After(time.Second)

	cc.L.Lock()
	// Passing func that gets channel c that signals when
	// Signal or Broadcast is called on CondChan
	cc.Select(func(c <-chan struct{}) { // Waiting with select
		select {
		case <-c: // Never ending wait
		case <-timeoutChan:
			fmt.Println("Hooray! Just escaped from eternal wait.")
		}
	})
	cc.L.Unlock()
}