Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate the connection context to exported methods. #374

Open
miccoli opened this issue Jul 31, 2023 · 0 comments
Open

Propagate the connection context to exported methods. #374

miccoli opened this issue Jul 31, 2023 · 0 comments

Comments

@miccoli
Copy link

miccoli commented Jul 31, 2023

If I got it right, each connection has an associated context, accessible as func (*Conn)Context, however this context is not available to exported methods.

It would be nice if the connection context could be propagate to the exported methods, something like this:

type service struct{}

func (s service) MethodWithContext(ctx context.Context) (err *dbus.Error) {
	// propagate DBus connection ctx
	// ...
	return
}

// ...

func main() {
	var s service

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	conn, err := dbus.ConnectSessionBus(dbus.WithContext(ctx))
	// ...        
	err = conn.Export(s, "/com/example/Object", "com.example.Interface")
	// ...        

}

The use case is clear: in the above MethodWithContext I have to call some long running routines that require a context argument. The context should be able to cross the API boundary so that cancellation/cleanup is possible when the connection is closed.

For now I'm forced to write

func (s service) MethodWithContext() (err *dbus.Error) {
	ctx := context.TODO()
	// ...
	return
}

which is suboptimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant