고루틴 데몬

1 개요[ | ]

간단한 고루틴 데몬
package main

import (
	"fmt"
	"time"
)

func main() {
	quitCh := make(chan bool)
	go daemon(quitCh)
	time.Sleep(3 * time.Second)
	quitCh <- true
	fmt.Println("main:", time.Now())
	time.Sleep(3 * time.Second)
	fmt.Println("main:", time.Now())
}

func daemon(quitCh chan bool) {
	for {
		select {
		case <-quitCh:
			return
		default:
			fmt.Println("daemon:", time.Now())
			time.Sleep(time.Second)
		}
	}
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}