asyn_wasm

package module
v0.0.5 Latest Latest
Warning

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

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

README

== Async WASM
Golang WASM oriented library-adaptor for JavaScript.

Golang 1.4 version is not support multi-thread development pattern at all (chanel usage can bring application to dead-lock) and only one way to develop `WASM` useful application is to utilize power of js Promise.

== Environment
Library developed only for followed compilation requirements:

* `GOARCH=wasm`
* `GOOS=js`
* build tags: `js, wasm`


EXAMPLE:
[source,bash]
----
$ GOARCH=wasm GOOS=js go build -tags js,wasm -o lib.wasm main.go
----

== Implemented
* [ ] Promise
* [ ] WebSocket


== Similar projects
* https://github.com/dennwc/dom
* https://github.com/dominikh/go-js-dom
* https://github.com/nhooyr/websocket


== MIT License
See the <<LICENSE#,LICENSE>>.

Documentation

Rendered for js/wasm

Index

Constants

View Source
const (
	WsConnecting = 0
	WsOpen       = 1
	WsClosing    = 2
	WsClosed     = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MsgCallBack added in v0.0.3

type MsgCallBack func(string) (interface{}, error)

type Promise

type Promise struct {
	// contains filtered or unexported fields
}

Promise implement js.Promise

func NewPromise

func NewPromise() *Promise

func (*Promise) JSValue

func (p *Promise) JSValue() js.Value

JSValue is actual js Promise object which should be returned by js.Func into real js runtime

func (*Promise) Reject

func (p *Promise) Reject(res interface{})

reject promise

func (*Promise) Resolve

func (p *Promise) Resolve(res interface{})

resolve promise

type WebSocket

type WebSocket struct {
	// contains filtered or unexported fields
}

WebSocket represent ws JavaScript adapter https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

func NewWebSocket added in v0.0.2

func NewWebSocket(host string, reconnect bool, cb MsgCallBack) *WebSocket

NewWebSocket create JS WebSocket adapter @host - URI with wss:// or ws:// format @reconnect - enable reconnection operation during close connection or during send attempt to closed connection

func (*WebSocket) Connect added in v0.0.2

func (w *WebSocket) Connect() js.Value

Connect evaluate connection operation to provided host @return JS Promise where would be send connection result

func (*WebSocket) ReadyState

func (w *WebSocket) ReadyState() int

func (*WebSocket) Send

func (w *WebSocket) Send(msg string) js.Value

@return JS Promise where would be putted further response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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