github.com/iotexproject/iotex-core@v1.14.1-rc1/actpool/options.go (about)

     1  // Copyright (c) 2019 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package actpool
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/facebookgo/clock"
    12  )
    13  
    14  // ActQueueOption is the option for actQueue.
    15  type ActQueueOption interface {
    16  	SetActQueueOption(*actQueue)
    17  }
    18  
    19  type clockOption struct{ c clock.Clock }
    20  
    21  // WithClock returns an option to overwrite clock.
    22  func WithClock(c clock.Clock) interface{ ActQueueOption } {
    23  	return &clockOption{c}
    24  }
    25  
    26  func (o *clockOption) SetActQueueOption(aq *actQueue) { aq.clock = o.c }
    27  
    28  type ttlOption struct{ ttl time.Duration }
    29  
    30  // WithTimeOut returns an option to overwrite time out setting.
    31  func WithTimeOut(ttl time.Duration) interface{ ActQueueOption } {
    32  	return &ttlOption{ttl}
    33  }
    34  
    35  func (o *ttlOption) SetActQueueOption(aq *actQueue) { aq.ttl = o.ttl }