Documentation ¶
Index ¶
- Variables
- func Await(awaitable js.Value) ([]js.Value, []js.Value)
- func BindAsyncFuncs(global js.Value, fnList map[string]interface{})
- func BindFunc(global js.Value, jsFuncName string, fn interface{}) error
- func BindFuncs(global js.Value, fnList map[string]interface{})
- func Close()
- func GetSelfWorker() *worker.GlobalSelf
- func NewArray(items ...interface{}) js.Value
- func NewBytes(buf []byte) js.Value
- func NewJsError(message interface{}) js.Value
- func NewObject(obj interface{}) js.Value
- func NewSelfWorker() (*worker.GlobalSelf, error)
- func RemoveWorker(blobberID string)
- type AsyncInvoker
- type Bytes
- type FileReader
- type FileWriter
- type InputBinder
- type InputBuilder
- type OutputBinder
- type OutputBuilder
- type SyncInvoker
- type Timer
- type WasmWebWorker
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMismatchedInputLength the length of input are mismatched ErrMismatchedInputLength = errors.New("binder: mismatched input length") // ErrMismatchedOutputLength the length of output are mismatched ErrMismatchedOutputLength = errors.New("binder: mismatched output length") // ErrBinderNotImplemented the type binder is not implemented yet ErrBinderNotImplemented = errors.New("binder: not impelmented") // ErrFuncNotSupported the type function is not supported yet ErrFuncNotSupported = errors.New("func: not supported") // ErrIsNotFunc bind works with func only ErrIsNotFunc = errors.New("func: bind works with func only") )
var ( TypeFunc = reflect.TypeOf(func() {}).String() TypeError = "error" TypeString = reflect.TypeOf("string").String() TypeBytes = reflect.TypeOf([]byte{}).String() )
var WorkerJSTpl []byte
Functions ¶
func Await ¶
This function try to execute wasm functions that are wrapped with "Promise" see: https://stackoverflow.com/questions/68426700/how-to-wait-a-js-async-function-from-golang-wasm/68427221#comment120939975_68427221
func BindAsyncFuncs ¶ added in v1.3.5
func BindFunc ¶
BindFunc bind go func to js func in global only support - func(...) - func(...) error - func(...) T - func(...) (T,error)
func GetSelfWorker ¶ added in v1.15.4
func GetSelfWorker() *worker.GlobalSelf
func NewJsError ¶
func NewSelfWorker ¶ added in v1.15.4
func NewSelfWorker() (*worker.GlobalSelf, error)
func RemoveWorker ¶ added in v1.15.4
func RemoveWorker(blobberID string)
Types ¶
type AsyncInvoker ¶
type Bytes ¶ added in v1.8.13
type Bytes struct {
Buffer []byte
}
func (*Bytes) UnmarshalJSON ¶ added in v1.8.13
type FileReader ¶ added in v1.8.12
type FileReader struct {
// contains filtered or unexported fields
}
func NewFileReader ¶ added in v1.8.12
func NewFileReader(readChunkFuncName string, fileSize, chunkReadSize int64) (*FileReader, error)
type FileWriter ¶ added in v1.11.4
type FileWriter struct {
// contains filtered or unexported fields
}
func NewFileWriter ¶ added in v1.11.4
func NewFileWriter(filename string) (*FileWriter, error)
func (*FileWriter) Close ¶ added in v1.11.4
func (w *FileWriter) Close() error
func (*FileWriter) Seek ¶ added in v1.11.4
func (w *FileWriter) Seek(offset int64, whence int) (int64, error)
func (*FileWriter) Sync ¶ added in v1.11.4
func (w *FileWriter) Sync() error
type InputBinder ¶
InputBinder convert inputs from js.Value to reflect.Value
type InputBuilder ¶
type InputBuilder struct { IsVariadic bool // contains filtered or unexported fields }
InputBuilder binder builder
func NewInputBuilder ¶
func NewInputBuilder(fn reflect.Type) *InputBuilder
NewInputBuilder create InputBuilder
func (*InputBuilder) Build ¶
func (b *InputBuilder) Build() (InputBinder, error)
Build build InputBinder js.ValueOf returns x as a JavaScript value:
| Go | JavaScript | | ---------------------- | ---------------------- | | js.Value | [its value] | | js.Func | function | | nil | null | | bool | boolean | | integers and floats | number | | string | string | | []interface{} | new array | | map[string]interface{} | new object |
Panics if x is not one of the expected types.
type OutputBinder ¶
OutputBinder convert Outputs from js.Value to reflect.Value
type OutputBuilder ¶
type OutputBuilder struct {
// contains filtered or unexported fields
}
OutputBuilder binder builder
func NewOutputBuilder ¶
func NewOutputBuilder(fn reflect.Type) *OutputBuilder
NewOutputBuilder create OutputBuilder
func (*OutputBuilder) Bind ¶
func (b *OutputBuilder) Bind(args []reflect.Value) []js.Value
Bind bind js Outputs to reflect values
func (*OutputBuilder) Build ¶
func (b *OutputBuilder) Build() (OutputBinder, error)
Build build OutputBinder js.ValueOf returns x as a JavaScript value:
| Go | JavaScript | | ---------------------- | ---------------------- | | js.Value | [its value] | | js.Func | function | | nil | null | | bool | boolean | | integers and floats | number | | string | string | | []interface{} | new array | | map[string]interface{} | new object |
Panics if x is not one of the expected types.
type SyncInvoker ¶ added in v1.3.5
type WasmWebWorker ¶ added in v1.15.4
type WasmWebWorker struct { // Name specifies an identifying name for the DedicatedWorkerGlobalScope representing the scope of the worker, which is mainly useful for debugging purposes. // If this is not specified, `Start` will create a UUIDv4 for it and populate back. Name string // Path is the path of the WASM to run as the Web Worker. // This can be a relative path on the server, or an abosolute URL. Path string // Args holds command line arguments, including the WASM as Args[0]. // If the Args field is empty or nil, Run uses {Path}. Args []string // Env specifies the environment of the process. // Each entry is of the form "key=value". // If Env is nil, the new Web Worker uses the current context's // environment. // If Env contains duplicate environment keys, only the last // value in the slice for each duplicate key is used. Env []string // contains filtered or unexported fields }
func GetWorker ¶ added in v1.15.4
func GetWorker(blobberID string) *WasmWebWorker
func NewWasmWebWorker ¶ added in v1.15.4
func NewWasmWebWorker(blobberID, blobberURL, clientID, publicKey, privateKey, mnemonic string) (*WasmWebWorker, error)
func (*WasmWebWorker) Listen ¶ added in v1.15.4
func (ww *WasmWebWorker) Listen(ctx context.Context) (<-chan worker.MessageEvent, error)
Listen sends message events on a channel for events fired by self.postMessage() calls inside the Worker's global scope. Stops the listener and closes the channel when ctx is canceled.
func (*WasmWebWorker) PostMessage ¶ added in v1.15.4
PostMessage sends data in a message to the worker, optionally transferring ownership of all items in transfers.
func (*WasmWebWorker) Start ¶ added in v1.15.4
func (ww *WasmWebWorker) Start() error
func (*WasmWebWorker) Terminate ¶ added in v1.15.4
func (ww *WasmWebWorker) Terminate()
Terminate immediately terminates the Worker.