worker

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package worker contains Go web-worker WASM module bridge methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindValue

func BindValue(val js.Value, dest interface{}) error

BindValue binds JS value to specified target

func FuncOf

func FuncOf(fn Func) js.Func

FuncOf wraps function into js-compatible async function with callback

func NewTypeError

func NewTypeError(expType, gotType js.Type) error

NewTypeError creates a new type error

func ParseArgs

func ParseArgs(allArgs []js.Value) (Args, Callback, error)

ParseArgs parses async call arguments.

Function expects the last argument to be a callable JS function

Types

type Args

type Args []js.Value

Args is collection if function call arguments

func (Args) Bind

func (args Args) Bind(targets ...interface{}) error

Bind binds passed JS arguments to Go values

Function supports *int, *bool, *string and ValueUnmarshaler values.

func (Args) BindIndex

func (args Args) BindIndex(index int, dest interface{}) error

BindIndex binds argument at specified index to passed value

type Callback

type Callback = func(interface{}, error)

Callback is async function callback

type Func

type Func = func(this js.Value, args Args) (interface{}, error)

Func is worker handler function

type Response

type Response struct {
	Error  string      `json:"error,omitempty"`
	Result interface{} `json:"result,omitempty"`
}

func NewErrorResponse

func NewErrorResponse(err error) Response

func NewResponse

func NewResponse(result interface{}, err error) Response

func (Response) JSON

func (r Response) JSON() string

type ValueUnmarshaler

type ValueUnmarshaler interface {
	UnmarshalValue(js.Value) error
}

Jump to

Keyboard shortcuts

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