Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.16 KB

README.md

File metadata and controls

50 lines (36 loc) · 1.16 KB

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.