Skip to content
Node: Promise.all, timersgithub.com/sahilkhaire/gox/async

Timeout

Overview

Timeout runs fn with a deadline derived from ctx and timeout.

Part of the async package — Node.js analog: Promise.all, timers.

Signature

go
func Timeout(ctx context.Context, timeout time.Duration, fn func(context.Context) error) error

Compare: Node.js · Standard Go · gox

js
// Typical Promise.all, timers pattern in Node.js
go
// Loop with backoff or context.WithTimeout
go
import "github.com/sahilkhaire/gox/async"

err := async.Timeout(ctx, 5*time.Second, func(ctx context.Context) error {
    return work(ctx)
})

Example

go
import "github.com/sahilkhaire/gox/async"

err := async.Timeout(ctx, 5*time.Second, func(ctx context.Context) error {
    return work(ctx)
})

Tips

All async helpers respect context cancellation — prefer them over raw goroutines when you need timeouts.

Standard library alternative

gox wraps the Go standard library or a trusted dependency with Node-familiar naming. You can use the underlying library directly — see the package overview for escape hatches.

Back to async package overview

MIT Licensed · Built for Node.js developers moving to Go