Documentation
¶
Index ¶
- func Await(p js.Value) (js.Value, error)
- func AwaitContext(ctx context.Context, p js.Value) (js.Value, error)
- func BytesToGo(v js.Value) []byte
- func BytesToJs(v []byte) js.Value
- func Get(v js.Value, ps ...string) (js.Value, bool)
- func GetX(v js.Value, ps ...string) js.Value
- func NewError(msg string) js.Value
- func NewReadableStream(r io.ReadCloser) js.Value
- func NewReader(v js.Value) (io.ReadCloser, error)
- func Object(v map[string]any) js.Value
- func Promise(f func() (any, any)) js.Value
- func Reject(v js.Value) js.Value
- func Resolve(v js.Value) js.Value
- func Stringify(jv js.Value) string
- func Unmarshal(data js.Value, v any) error
- type FetchTransport
- type RejectedError
- type Scope
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Await ¶
Await waits for a JavaScript Promise to resolve and returns its result. If the Promise is rejected, an error is returned.
func AwaitContext ¶
AwaitContext waits for a JavaScript Promise to resolve with context support. The wait can be cancelled via the provided context.
func Get ¶
Get navigates through nested JavaScript object properties. Returns the final value and true if all properties exist, or js.Undefined and false otherwise.
func GetX ¶
GetX navigates through nested JavaScript object properties without checking existence. Returns js.Undefined if any property in the path doesn't exist.
func NewReadableStream ¶
func NewReadableStream(r io.ReadCloser) js.Value
func Promise ¶
Promise creates a JavaScript Promise from a Go function. The function f should return a result value and an error. If the error is not nil, the Promise will be rejected.
Note: Unlike a JavaScript `new Promise((resolve, reject) => { ... })` executor, the function you pass is not run synchronously during construction. It is deferred and executed in a separate goroutine after the current call returns. Therefore, any side effects or panics inside the function will not be observable in the immediate calling context.
Types ¶
type FetchTransport ¶
type FetchTransport struct{}
type RejectedError ¶
func (RejectedError) Error ¶
func (e RejectedError) Error() string
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
func GlobalScope ¶
func GlobalScope() *Scope
GlobalScope returns the global Scope instance that can be used to manage JavaScript function lifecycles and wait for their completion.