message

package
v0.16.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package message provides a generic mechanism for sending messages to and receiving replies from a Service Worker. The application defines its own message types and commands on top of this transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterReplyType

func RegisterReplyType(msgType string)

RegisterReplyType registers a message type that the listener should capture. Must be called before Send for each expected reply type.

Types

type Reply

type Reply struct {
	Raw js.Value // the entire data object of the message
}

Reply represents the response received from the Service Worker.

func Send

func Send(msgType string, replyType string, msg map[string]any) (Reply, error)

Send sends a message to the Service Worker and blocks until a reply is received. The "type" and "requestId" fields are added automatically to the msg map. replyType is the message type that the SW should use in the response.

func (Reply) Error

func (r Reply) Error() string

Error returns the "error" field of the response, or "".

func (Reply) Get

func (r Reply) Get(key string) js.Value

Get returns the value of an arbitrary field from the response.

func (Reply) OK

func (r Reply) OK() bool

OK returns the value of the "ok" field of the response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL