Commit f615b0e2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d293272d
...@@ -58,6 +58,8 @@ func Canceled(err error) bool { ...@@ -58,6 +58,8 @@ func Canceled(err error) bool {
// //
// func myfunc(ctx, ...) { // func myfunc(ctx, ...) {
// defer xcontext.WhenDone(ctx, func() { ... })() // defer xcontext.WhenDone(ctx, func() { ... })()
//
// XXX -> use WithCloseOnErrCancel instead?
func WhenDone(ctx context.Context, f func()) func() { func WhenDone(ctx context.Context, f func()) func() {
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
......
// Copyright (C) 2017-2020 Nexedi SA and Contributors. // Copyright (C) 2017-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -54,6 +54,8 @@ func EOFok(err error) error { ...@@ -54,6 +54,8 @@ func EOFok(err error) error {
// defer xio.CloseWhenDone(ctx, c)() // defer xio.CloseWhenDone(ctx, c)()
// //
// The error - if c.Close() returns with any - is logged. // The error - if c.Close() returns with any - is logged.
//
// XXX -> use xcontext.WithCloseOnErrCancel instead?
func CloseWhenDone(ctx context.Context, c io.Closer) func() { func CloseWhenDone(ctx context.Context, c io.Closer) func() {
return xcontext.WhenDone(ctx, func() { return xcontext.WhenDone(ctx, func() {
err := c.Close() err := c.Close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment