Documentation
¶
Index ¶
- func ExpandArgs(args []js.Value, target ...*js.Value)
- func FromJSON(s string) js.Value
- func Log(format string, objs ...interface{})
- func LogDebug(format string, objs ...interface{})
- func LogError(format string, objs ...interface{})
- func NewObject() js.Value
- func ObjectKeys(val js.Value) ([]string, error)
- func OneTimeFuncOf(f func(this js.Value, args []js.Value) interface{}) js.Func
- func SetTimeout(timeout time.Duration, callback func())
- func SingleArg(args []js.Value) js.Value
- func ToJSON(val js.Value) string
- type AsyncContext
- type CleanupFunc
- type CleanupFuncs
- type JSError
- type Promise
- type RejectFunc
- type ResolveFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandArgs ¶
ExpandArgs unpacks function arguments to target values.
func Log ¶
func Log(format string, objs ...interface{})
Log logs general information to the Javascript Console.
func LogDebug ¶
func LogDebug(format string, objs ...interface{})
LogDebug logs a debug message to the Javascript Console.
func LogError ¶
func LogError(format string, objs ...interface{})
LogError logs an error to the Javascript Console.
func ObjectKeys ¶
ObjectKeys returns the keys for a given object.
func OneTimeFuncOf ¶
OneTimeFuncOf returns a js.Func that can be invoked once. It is automatically released when invoked.
func SetTimeout ¶
SetTimeout registers a callback to be invoked when the timeout has expired.
Types ¶
type AsyncContext ¶
type AsyncContext interface { // AFunc is a dummy method to avoid arbitrary types from satisfying this // interface. AFunc() }
AsyncContext is a type of context passed to a function executing asynchronously.
type CleanupFunc ¶
type CleanupFunc func()
CleanupFunc is a function to be invoked to cleanup resources.
func DefineAsyncFunc ¶
func DefineAsyncFunc(o js.Value, name string, f func(ctx AsyncContext, this js.Value, args []js.Value) (js.Value, error)) CleanupFunc
DefineAsyncFunc defines a new async function and attaches it to the specified object. The defined function will return a promise that is resolved or rejected when it completes. The returned cleanup function must be invoked to detach the function and release it.
func DefineFunc ¶
func DefineFunc(o js.Value, name string, f func(this js.Value, args []js.Value) interface{}) CleanupFunc
DefineFunc defines a new function and attaches it to the specified object. The returned cleanup function must be invoked to detach the function and release it.
type CleanupFuncs ¶
type CleanupFuncs struct {
// contains filtered or unexported fields
}
CleanupFuncs is a set of cleanup functions.
type JSError ¶
JSError represents javascript's Error type.
func NewErrorFromVal ¶
NewErrorFromVal returns a Javascript error corresponding to an arbitrary value. We do our best to preserve the original value, but we do assume that it reflects an error and is not some arbitrary value.
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
Promise encapsulates a javascript Promise type.
func AsPromise ¶
AsPromise returns a Promise for javascript value. The value is assumed to be of the Promise type.
func Async ¶
func Async(f func(ctx AsyncContext) (js.Value, error)) *Promise
Async executes a function asynchronously. A promise corresponding to the function is returned.
func NewPromise ¶
func NewPromise(f func(ctx AsyncContext, resolve ResolveFunc, reject RejectFunc)) *Promise
NewPromise runs a function in the background. The function must invoke resolve or reject when complete. The function is passed an AsyncContext which can then be used to invoke Await() on promises that it subsequently creates.
func (*Promise) Await ¶
func (p *Promise) Await(ctx AsyncContext) (js.Value, error)
Await blocks until a Promise is either resolved or rejected. It must only be invoked from within an AsyncContext.
func (*Promise) Then ¶
func (p *Promise) Then(resolve ResolveFunc, reject RejectFunc) *Promise
Then implements Promise.then(). Resolve is invoked when the promise is resolved, and reject is invoked when it is rejected.
type RejectFunc ¶
type RejectFunc func(err error)
RejectFunc is a function type that can be used to reject a promise.
type ResolveFunc ¶
ResolveFunc is a function type that can be used to resolve a promise.