Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.54 KB

README.md

File metadata and controls

44 lines (33 loc) · 1.54 KB

Fillmore Labs LazyDone

Go Reference Test Coverage Maintainability Go Report Card License

The lazydone package provides a lazy initialized done channel with a valid zero value in Go.

Usage

package main

import (
	"fmt"
	"time"

	"fillmore-labs.com/lazydone"
)

type Result struct {
	lazydone.Lazy
	value int
}

func main() {
	var result Result

	go func() {
		time.Sleep(100 * time.Millisecond)
		result.value = 42
		result.Close() // The result is ready.
	}()

	<-result.Done() // Wait for the result.
	fmt.Println("Value:", result.value)
}

The channel can be used in select statements, which is not possible with Mutexes or WaitGroups.