github.com/andy2046/gopie@v0.7.0/pkg/sequence/sequencer.go (about)

     1  // Package sequence implements Iceflake sequence generator interface.
     2  // ```bash
     3  // Iceflake is the interface for snowflake similar sequence generator.
     4  //
     5  // Iceflake algorithm:
     6  //
     7  // +-------+--------------------+----------+
     8  // | sign  | delta milliseconds | sequence |
     9  // +-------+--------------------+----------+
    10  // | 1 bit | 63-n bits          | n bits   |
    11  //
    12  // sequence (n bits)
    13  // The last custom n bits, represents sequence within the one millisecond.
    14  //
    15  // delta milliseconds (63-n bits)
    16  // The next 63-n bits, represents delta milliseconds since a custom epoch.
    17  // ```
    18  package sequence
    19  
    20  // Sequencer is the interface for sequence generator.
    21  type Sequencer interface {
    22  	// Next returns the next sequence.
    23  	Next() (uint64, error)
    24  	// NextN reserves the next `n` sequences and returns the first one,
    25  	// `n` should not be less than 1.
    26  	NextN(n int) (uint64, error)
    27  	// MachineID returns the unique ID of the instance.
    28  	MachineID() uint64
    29  }