github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/dispatcher.go (about)

     1  package actor
     2  
     3  type Dispatcher interface {
     4  	Schedule(fn func())
     5  	Throughput() int
     6  }
     7  
     8  type goroutineDispatcher int
     9  
    10  var _ Dispatcher = goroutineDispatcher(0)
    11  
    12  func (goroutineDispatcher) Schedule(fn func()) {
    13  	go fn()
    14  }
    15  
    16  func (d goroutineDispatcher) Throughput() int {
    17  	return int(d)
    18  }
    19  
    20  func NewDefaultDispatcher(throughput int) Dispatcher {
    21  	return goroutineDispatcher(throughput)
    22  }
    23  
    24  type synchronizedDispatcher int
    25  
    26  var _ Dispatcher = synchronizedDispatcher(0)
    27  
    28  func (synchronizedDispatcher) Schedule(fn func()) {
    29  	fn()
    30  }
    31  
    32  func (d synchronizedDispatcher) Throughput() int {
    33  	return int(d)
    34  }
    35  
    36  func NewSynchronizedDispatcher(throughput int) Dispatcher {
    37  	return synchronizedDispatcher(throughput)
    38  }