split queues.batchSendOptions

This commit is contained in:
syumai 2024-11-09 23:51:23 +09:00
parent 488aec9585
commit b54a5edc0d
2 changed files with 36 additions and 28 deletions

View File

@ -0,0 +1,36 @@
package queues
import (
"syscall/js"
"time"
"github.com/syumai/workers/internal/jsutil"
)
type batchSendOptions struct {
// DelaySeconds - The number of seconds to delay the message.
// Default is 0
DelaySeconds int
}
func (o *batchSendOptions) toJS() js.Value {
if o == nil {
return js.Undefined()
}
obj := jsutil.NewObject()
if o.DelaySeconds != 0 {
obj.Set("delaySeconds", o.DelaySeconds)
}
return obj
}
type BatchSendOption func(*batchSendOptions)
// WithBatchDelay changes the number of seconds to delay the message.
func WithBatchDelay(d time.Duration) BatchSendOption {
return func(o *batchSendOptions) {
o.DelaySeconds = int(d.Seconds())
}
}

View File

@ -36,31 +36,3 @@ func WithDelay(d time.Duration) SendOption {
o.DelaySeconds = int(d.Seconds()) o.DelaySeconds = int(d.Seconds())
} }
} }
type batchSendOptions struct {
// DelaySeconds - The number of seconds to delay the message.
// Default is 0
DelaySeconds int
}
func (o *batchSendOptions) toJS() js.Value {
if o == nil {
return js.Undefined()
}
obj := jsutil.NewObject()
if o.DelaySeconds != 0 {
obj.Set("delaySeconds", o.DelaySeconds)
}
return obj
}
type BatchSendOption func(*batchSendOptions)
// WithBatchDelay changes the number of seconds to delay the message.
func WithBatchDelay(d time.Duration) BatchSendOption {
return func(o *batchSendOptions) {
o.DelaySeconds = int(d.Seconds())
}
}