charmbracelet / charmbracelet/bubbletea

Pass Context to Init?

Open
#756 3 comments 1 reaction 0 assignees View on GitHub
question v2
Dominant language
Go
Stars
44.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I have a use case like the HTTP example, except the external client expects a context:

```
type Client interface {
Call(context.Context)
}

type model struct {
client Client
}

func (m model) Init() {
m.client.Call( ¯\_(ツ)_/¯ )
}
```
What's the "right" way to structure this? I found `tea.WithContext` but it's not clear if or how I can actually access the program's context elsewhere. I could just do this with a channel (like the realtime example) or perhaps a closure, but I'm curious if there's a pattern you like for this kind of thing.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.