Skip to content

Modern Chan WithTimeout

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Goroutines and Channels › Goroutines and Channels › WithTimeout

WithTimeout

Returns a child context that cancels itself after the given milliseconds.

Syntax

WithTimeout( parent, ms )

Notes

  • cancels itself when the deadline passes

Examples

#import "std/tasks"
using tasks

dim root as Context
dim ctx as CancelContext = WithTimeout( root, 50 )

print ctx.IsCancelled( )     '' false

sleep 150, 1
print ctx.IsCancelled( )     '' true
print ctx.Err( )             '' deadline exceeded -- NOT "cancelled"

'' The timeout is a goroutine parked with a deadline, so it costs one
'' pool worker for the duration. Cancelling early unparks it, so it does
'' not outlive the context.

Library: Goroutines and Channels
Category: Goroutines and Channels
Documented under: Context

Clone this wiki locally