2024-10-11 11:41:24 +02:00
|
|
|
package queues
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall/js"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/syumai/workers/internal/jsutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
type sendOptions struct {
|
|
|
|
// ContentType - Content type of the message
|
|
|
|
// Default is "json"
|
2024-11-09 23:24:30 +09:00
|
|
|
ContentType contentType
|
2024-10-11 11:41:24 +02:00
|
|
|
|
|
|
|
// DelaySeconds - The number of seconds to delay the message.
|
|
|
|
// Default is 0
|
|
|
|
DelaySeconds int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *sendOptions) toJS() js.Value {
|
|
|
|
obj := jsutil.NewObject()
|
|
|
|
obj.Set("contentType", string(o.ContentType))
|
|
|
|
|
|
|
|
if o.DelaySeconds != 0 {
|
|
|
|
obj.Set("delaySeconds", o.DelaySeconds)
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
type SendOption func(*sendOptions)
|
|
|
|
|
2024-11-10 00:07:29 +09:00
|
|
|
// WithDelaySeconds changes the number of seconds to delay the message.
|
|
|
|
func WithDelaySeconds(d time.Duration) SendOption {
|
2024-10-11 11:41:24 +02:00
|
|
|
return func(o *sendOptions) {
|
|
|
|
o.DelaySeconds = int(d.Seconds())
|
|
|
|
}
|
|
|
|
}
|