Skip to content

Commit

Permalink
Rename to SendAndGetID
Browse files Browse the repository at this point in the history
  • Loading branch information
markuswustenberg committed May 27, 2024
1 parent 118fd39 commit f90c5b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions goqite.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,24 @@ func (q *Queue) Send(ctx context.Context, m Message) error {

// SendTx is like Send, but within an existing transaction.
func (q *Queue) SendTx(ctx context.Context, tx *sql.Tx, m Message) error {
_, err := q.SendAndReturnIDTx(ctx, tx, m)
_, err := q.SendAndGetIDTx(ctx, tx, m)
return err
}

// SendAndReturnID is like Send, but also returns the message ID.
func (q *Queue) SendAndReturnID(ctx context.Context, m Message) (ID, error) {
// SendAndGetID is like Send, but also returns the message ID, which can be used
// to interact with the message without receiving it first.
func (q *Queue) SendAndGetID(ctx context.Context, m Message) (ID, error) {
var id ID
err := internalsql.InTx(q.db, func(tx *sql.Tx) error {
var err error
id, err = q.SendAndReturnIDTx(ctx, tx, m)
id, err = q.SendAndGetIDTx(ctx, tx, m)
return err
})
return id, err
}

// SendAndReturnIDTx is like SendAndReturnID, but within an existing transaction.
func (q *Queue) SendAndReturnIDTx(ctx context.Context, tx *sql.Tx, m Message) (ID, error) {
// SendAndGetIDTx is like SendAndGetID, but within an existing transaction.
func (q *Queue) SendAndGetIDTx(ctx context.Context, tx *sql.Tx, m Message) (ID, error) {
if m.Delay < 0 {
panic("delay cannot be negative")
}
Expand Down
4 changes: 2 additions & 2 deletions goqite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ func TestQueue_Receive(t *testing.T) {
})
}

func TestQueue_SendAndReturnID(t *testing.T) {
func TestQueue_SendAndGetID(t *testing.T) {
t.Run("returns the message ID", func(t *testing.T) {
q := newQ(t, goqite.NewOpts{}, ":memory:")

m := goqite.Message{
Body: []byte("yo"),
}

id, err := q.SendAndReturnID(context.Background(), m)
id, err := q.SendAndGetID(context.Background(), m)
is.NotError(t, err)
is.Equal(t, 34, len(id))

Expand Down

0 comments on commit f90c5b8

Please sign in to comment.