lease

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2021 License: MIT Imports: 1 Imported by: 0

README

Usage

lease the resource for duration. When the lease expires, invoke func

Example

package main 

import (
	"github.com/donutloop/toolkit/lease"
)

func main() {
    leaser := lease.NewLeaser()
    leaser.Lease("cleanup-cache", time.Duration(1*time.Second), func() {
    	fmt.Println("cleaned up cache")
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Leaser

type Leaser interface {
	// lease the resource r for duration. When the lease expires, invoke func call.
	// revoke a lease can be refreshed by calling Lease() again on the same resource.
	Lease(r string, d time.Duration, revoke func())
	// if resource exists then cancel the old timer and delete the entry.
	Return(r string) bool
}

func NewLeaser

func NewLeaser() Leaser

NewLeaser creates a instance of leaser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL