github.com/gogf/gf/v2@v2.7.4/os/gctx/gctx_never_done.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gctx
     8  
     9  import (
    10  	"context"
    11  	"time"
    12  )
    13  
    14  // neverDoneCtx never done.
    15  type neverDoneCtx struct {
    16  	context.Context
    17  }
    18  
    19  // Done forbids the context done from parent context.
    20  func (*neverDoneCtx) Done() <-chan struct{} {
    21  	return nil
    22  }
    23  
    24  // Deadline forbids the context deadline from parent context.
    25  func (*neverDoneCtx) Deadline() (deadline time.Time, ok bool) {
    26  	return time.Time{}, false
    27  }
    28  
    29  // Err forbids the context done from parent context.
    30  func (c *neverDoneCtx) Err() error {
    31  	return nil
    32  }
    33  
    34  // NeverDone wraps and returns a new context object that will be never done,
    35  // which forbids the context manually done, to make the context can be propagated
    36  // to asynchronous goroutines.
    37  //
    38  // Note that, it does not affect the closing (canceling) of the parent context,
    39  // as it is a wrapper for its parent, which only affects the next context handling.
    40  func NeverDone(ctx context.Context) context.Context {
    41  	return &neverDoneCtx{ctx}
    42  }