---
title: WithTimeout
summary: WithTimeout returns a copy of the parent context which will be cancelled after the provided timeout. Unlike context.WithTimeout the deadline will not be adjusted, and it will not return the context.DeadlineExceeded error. Canceling before the timeout will not clean up the spawned goroutine however the goroutine will become a no-op. It is possible for pauses in Wasm execution to cause the timeout to be delayed. This should not be relied on for applications where a precise timout is required.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/x/fstctx/fn.WithTimeout/
---

**Kind:** Function  
**Module:** [fstctx](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/x/fstctx/)  
**Package:** compute-sdk-go v1.11.0  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/x/fstctx/ctxutil.go#L40

```go
func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
```

WithTimeout returns a copy of the parent context which will be cancelled
after the provided timeout. Unlike context.WithTimeout the deadline will not
be adjusted, and it will not return the context.DeadlineExceeded error.
Canceling before the timeout will not clean up the spawned goroutine
however the goroutine will become a no-op. It is possible for pauses in Wasm
execution to cause the timeout to be delayed. This should not be relied on
for applications where a precise timout is required.

Canceling this context releases resources associated with it, so code should
call cancel as soon as the operations running in this Context complete:

	func slowOperationWithTimeout(ctx context.Context) (Result, error) {
		ctx, cancel := fstctx.WithTimeout(ctx, 100*time.Millisecond)
		defer cancel()  // releases resources if slowOperation completes before timeout elapses
		return slowOperation(ctx)
	}

**Parameters**

- `parent`: `context.Context`
- `timeout`: `time.Duration`

**Returns**

`(context.Context, context.CancelFunc)`
