os

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 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

定时任务 提供周期性任务执行功能。使用方式类似于Linux下的Crontab或者Java里的Quartz。本对象线程安全。

Package cable implements utility functions for scheduling/limiting function calls

定时任务 提供周期性任务执行功能。使用方式类似于Linux下的Crontab或者Java里的Quartz。本对象线程安全。

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 E时钟_创建

func E时钟_创建(fn func() bool, 时钟周期 int64)

func E时钟_创建周期函数

func E时钟_创建周期函数(fn func(), 时钟周期 int64) func()

返回一个函数,无论调用多少次,它只会在指定的间隔内执行一次

func E时钟_创建执行一次

func E时钟_创建执行一次(fn func(), 时钟周期 int64)

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 E时钟

type E时钟 struct {
}

func New时钟

func New时钟() *E时钟

func (*E时钟) E创建

func (this *E时钟) E创建(fn func() bool, 时钟周期 int64)

func (*E时钟) E创建执行一次

func (this *E时钟) E创建执行一次(fn func(), 时钟周期 int64)

func (*E时钟) E时钟周期函数

func (this *E时钟) E时钟周期函数(fn func(), 时钟周期 int64) func()

返回一个函数,无论调用多少次,它只会在指定的间隔内执行一次

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