ncrated

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ncrated is [rated] package for nctask and ncaction.

Example
t := func() error { return nil }
timed := nctask.Task(t).Timed(time.Second)
rl := Task(rate.NewLimiter(rate.Every(time.Second), 1), t)

begin := time.Now()
timed.Run() // run t, wait a second
timed.Run() // run t, wait a second
timed.Run() // run t, wait a second
fmt.Printf("timed task: elapsed %d seconds\n", time.Since(begin)/time.Second)

begin = time.Now()
rl.Run() // run t
rl.Run() // wait a second, run t
rl.Run() // wait a second, run t
fmt.Printf("ratelimited task: elapsed %d seconds\n", time.Since(begin)/time.Second)
Output:
timed task: elapsed 3 seconds
ratelimited task: elapsed 2 seconds

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Data

func Data[T any](l *rate.Limiter, d ncaction.Data[T]) ncaction.Data[T]

Data creates an ncaction.Data that respects the rate limit, quite like Task.

There's no rate limited ncaction.Action or ncaction.Converter. For actions, rate limit should be applied on resulted task. For converters, it should be applied on resulted data.

func New deprecated

func New(l *rate.Limiter, t nctask.Task) (ret nctask.Task)

New creates a nctask.Task that respects the rate limit.

Say you have an empty task r with rate limit to once per second:

r.Run() // executed immediately
r.Run() // executed after a second

Deprecated: use Task instead.

func Task

func Task(l *rate.Limiter, t nctask.Task) nctask.Task

Task creates a nctask.Task that respects the rate limit.

Say you have an empty task r with rate limit to once per second:

r.Run() // executed immediately
r.Run() // executed after a second

Types

This section is empty.

Jump to

Keyboard shortcuts

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