github.com/haraldrudell/parl@v0.4.176/pnet/thread-source.go (about)

     1  /*
     2  © 2024–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pnet
     7  
     8  import (
     9  	"net"
    10  
    11  	"github.com/haraldrudell/parl"
    12  )
    13  
    14  // ThreadSource provides a thread-allocation strategy
    15  //   - when Receiver is invoked, threads can be pre-launched for
    16  //     a pending connection
    17  //   - default allocation strategy when ThreadSource is not used is
    18  //     one thread per connection
    19  //   - ThreadSource allows for any thread-allocation strategy to be used
    20  //     when handling multiple connections
    21  //   - when connReceiver.Handle is invoked, threads launched by Receiver
    22  //     may already be waiting at a a lock for maximum performance
    23  type ThreadSource[C net.Conn] interface {
    24  	// Receiver prepares the ThreadSource for a possible upcoming connection
    25  	//	- done will be invoked exactly once by all connReceiver objects
    26  	//	- to ensure done invocation, [ConnectionReceiver.Handle] or
    27  	//		[ConnectionReceiver.Shutdown] or both must be invoked
    28  	//	- Receiver and connReceiver.Handle do not block
    29  	//	- any connection provided to [ConnectionReceiver.Handle] is
    30  	//		guaranteed to be closed by Handle even if
    31  	//		[ConnectionReceiver.Shutdown] was already invoked
    32  	Receiver(done parl.Done, addError parl.AddError) (connReceiver ConnectionReceiver[C], err error)
    33  }