slow

package module
v0.0.0-...-de84e13 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2018 License: MIT Imports: 1 Imported by: 0

README

slow

Go package for Debounce and Throttle functions.
See stackoverflow answers for more details about what is throttle and debounce.

install

go get github.com/chneau/slow

usage

    ...
    i := 0
    fn := func() {
        i++
    }
    options := &slow.Options{
        Trailing: true,
        Leading:  true,
        MaxWait:  time.Millisecond * 500,
    }
    // options = nil // can be null, see defaults
    throttled := slow.Throttle(fn, time.Millisecond*50, options)
    debounced := slow.Debounce(fn, time.Millisecond*50, options)
    // the returned functions will be debounced / throttled.
    // so some calls will be no-op depending on the options
    throttled()
    throttled()
    ...

thanks

Thanks to lodash from where the implementation comes from.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debounce

func Debounce(fn func(), wait time.Duration, options *Options) func()

Debounce ...

leading := false

maxWait := time.Duration(0)

trailing := true

func Throttle

func Throttle(fn func(), wait time.Duration, options *Options) func()

Throttle ...

leading := true

maxWait := wait

trailing := true

Types

type Options

type Options struct {
	Leading  bool
	MaxWait  time.Duration
	Trailing bool
}

Options ...

Jump to

Keyboard shortcuts

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