github.com/searKing/golang/go@v1.2.117/sync/threaddo_options.go (about)

     1  // Code generated by "go-option -type=threadDo"; DO NOT EDIT.
     2  // Install go-option by "go get -u github.com/searKing/golang/tools/go-option"
     3  
     4  package sync
     5  
     6  // A ThreadDoOption sets options.
     7  type ThreadDoOption interface {
     8  	apply(*threadDo)
     9  }
    10  
    11  // EmptyThreadDoOption does not alter the configuration. It can be embedded
    12  // in another structure to build custom options.
    13  //
    14  // This API is EXPERIMENTAL.
    15  type EmptyThreadDoOption struct{}
    16  
    17  func (EmptyThreadDoOption) apply(*threadDo) {}
    18  
    19  // ThreadDoOptionFunc wraps a function that modifies threadDo into an
    20  // implementation of the ThreadDoOption interface.
    21  type ThreadDoOptionFunc func(*threadDo)
    22  
    23  func (f ThreadDoOptionFunc) apply(do *threadDo) {
    24  	f(do)
    25  }
    26  func (o *threadDo) ApplyOptions(options ...ThreadDoOption) *threadDo {
    27  	for _, opt := range options {
    28  		if opt == nil {
    29  			continue
    30  		}
    31  		opt.apply(o)
    32  	}
    33  	return o
    34  }
    35  
    36  // WiththreadDoEscapeThread sets EscapeThread in threadDo.
    37  // call the function f in the same thread or escape thread
    38  func WiththreadDoEscapeThread(v bool) ThreadDoOption {
    39  	return ThreadDoOptionFunc(func(o *threadDo) {
    40  		o.EscapeThread = v
    41  	})
    42  }