Skip to content

plzzzzg/waitonce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WaitOnce

Go Reference Go Go Report Card codecov

WaitOnce is a simple tool that ensures the prerequisites are ready.

Install

go get github.com/plzzzzg/waitonce

Examples

package main

import (
	"github.com/plzzzzg/waitonce"
	"time"
)

func main() {
	waitOnceID := "preload"

	go func() {
		if timeout := waitonce.GetOrCreate(waitOnceID).Wait(time.Second); timeout {
			// fallback when timeout
		} else {
			// do something after preloading done
		}
	}()

	// preload async
	go func() {
		// preloading
		time.Sleep(time.Second)
		waitonce.GetOrCreate(waitOnceID).Done()
	}()
}

Licence

Licensed under the MIT License.

About

WaitOnce is a simple tool that ensures the prerequisites are ready.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages