Skip to content

fillmore-labs/lazydone

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages