8000 GitHub - yudppp/throttle at v1.0.3
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

yudppp/throttle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

throttle

test workflow Go Report Card

Throttle is an object that will perform exactly one action per duration. Do call the function f if a specified duration has passed since the last function f was called for this instance of Throttle.

Group 38

example

go playground

package main

import (
	"fmt"
	"time"

	"github.com/yudppp/throttle"
)

func main() {
	throttler := throttle.New(time.Second)
	throttler.Do(func() {
		fmt.Println("first call")
	})
	throttler.Do(func() {
		// this function called never.
		fmt.Println("second call")
	})
	time.Sleep(time.Second)
	throttler.Do(func() {
		fmt.Println("third call")
	})
	time.Sleep(time.Second)
}

output

first call
third call

License

The MIT License (MIT)

About

lodash throttle like Go library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0