Skip to content
josestgPublic

About

A lazy value loader, it can be used to load expensive computation only when it is needed and cache the result for future use.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Lazy

A lazy value loader, it can be used to load expensive computation only when it is needed and cache the result for future use.

Installation

go get github.com/josestg/lazy

Example

package main

import (
	"fmt"
	"time"

	"github.com/josestg/lazy"
)

func main() {
	// Create a lazy value loader.
	l := lazy.New(func() (string, error) {
		time.Sleep(1 * time.Second)
		return "Hello, World!", nil
	})

	// Get the value for the first time will be slow.
	fmt.Println(l.Value())  // Hello, World!
	fmt.Println(l.Loaded()) // true

	// Get the value for the next will return the cached value.
	fmt.Println(l.Value()) // Hello, World!
	fmt.Println(l.Value()) // Hello, World!
}

About

A lazy value loader, it can be used to load expensive computation only when it is needed and cache the result for future use.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages