cable

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 2 Imported by: 0

README

build Software License Go Report Card Docs

Cable

Utility belt package for scheduling/limiting function calls (throttle, debounce, setTimeout, setInterval)

Install

go get github.com/jahnestacado/cable

API

func Throttle
func Throttle(f func(), interval time.Duration) func()

Throttle returns a function that no matter how many times it is invoked, it will only execute once within the specified interval

type ThrottleOptions
type ThrottleOptions struct {
	Immediate bool
}

ThrottleOptions is used to further configure the behavior of a throttled-function

func Debounce
func Debounce(f func(), interval time.Duration, options DebounceOptions) func()

Debounce returns a function that no matter how many times it is invoked, it will only execute after the specified interval has passed from its last invocation

type DebounceOptions
type DebounceOptions struct {
	Immediate bool
}

DebounceOptions is used to further configure the behavior of a debounced-function

func SetInterval
func SetInterval(f func() bool, interval time.Duration) func()

SetInterval executes function f repeatedly with a fixed time delay(interval) between each call until function f returns false. It returns a cancel function which can be used to cancel aswell the execution of function f

func SetTimeout
func SetTimeout(f func(), interval time.Duration) func()

SetTimeout postpones the execution of function f for the specified interval. It returns a cancel function which when invoked earlier than the specified interval, it will cancel the execution of function f. Note that function f is executed in a different goroutine

GoDoc for cable.go

License

Copyright (c) 2018 Ioannis Tzanellis
Released under the MIT license

Documentation

Overview

Package cable implements utility functions for scheduling/limiting function calls

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debounce

func Debounce(f func(), interval time.Duration, options DebounceOptions) func()

Debounce returns a function that no matter how many times it is invoked, it will only execute after the specified interval has passed from its last invocation

func SetInterval

func SetInterval(f func() bool, interval time.Duration) func()

SetInterval executes function f repeatedly with a fixed time delay(interval) between each call until function f returns false. It returns a cancel function which can be used to cancel aswell the execution of function f

func SetTimeout

func SetTimeout(f func(), interval time.Duration) func()

SetTimeout postpones the execution of function f for the specified interval. It returns a cancel function which when invoked earlier than the specified interval, it will cancel the execution of function f. Note that function f is executed in a different goroutine

func Throttle

func Throttle(f func(), interval time.Duration, options ThrottleOptions) func()

Throttle returns a function that no matter how many times it is invoked, it will only execute once within the specified interval

Types

type DebounceOptions

type DebounceOptions struct {
	Immediate bool
}

DebounceOptions is used to further configure the behavior of a debounced-function

type ThrottleOptions

type ThrottleOptions struct {
	Immediate bool
}

ThrottleOptions is used to further configure the behavior of a throttled-function

Jump to

Keyboard shortcuts

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