mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 09:27:08 +00:00
split queues.batchSendOptions
This commit is contained in:
parent
488aec9585
commit
b54a5edc0d
36
cloudflare/queues/batchsendoptions.go
Normal file
36
cloudflare/queues/batchsendoptions.go
Normal 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())
|
||||
}
|
||||
}
|
@ -36,31 +36,3 @@ func WithDelay(d time.Duration) SendOption {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user