示例#1
0
文件: main.go 项目: kevinherro/Exis
func (d *Domain) Register(endpoint string, handler *js.Object) *js.Object {
	cb := core.NewID()
	var p promise.Promise

	go func() {
		// From the want wrapper pull out the types they defined,
		// and pass them down into the core.
		h := handler.Get("types")
		tmp := h.Interface()
		types, hasTypes := tmp.([]interface{})

		// handler can either be:
		// 1. an object that contains "types" and "fp" attributes.
		// 2. a naked function, in which case we tell the core that it doesn't
		// care about types.
		handlerFunction := handler
		handlerTypes := []interface{}{nil}
		if hasTypes {
			handlerFunction = handler.Get("fp")
			handlerTypes = types
		}

		if err := d.coreDomain.Register(endpoint, cb, handlerTypes); err == nil {
			d.app.registrations[cb] = handlerFunction
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}
示例#2
0
文件: main.go 项目: kevinherro/Exis
// Turn the given invocation into a JS promise. If the function returns an error, return the error,
// else return the results of the function
func promisify(fn func() (interface{}, error)) *js.Object {
	var p promise.Promise

	go func() {
		if results, err := fn(); err == nil {
			p.Resolve(results)
		} else {
			p.Reject(err.Error())
		}
	}()

	return p.Js()
}
示例#3
0
文件: main.go 项目: newgogo/Exis
func (d *Domain) Leave() *js.Object {
	var p promise.Promise

	go func() {
		if err := d.coreDomain.Leave(); err == nil {
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}
示例#4
0
文件: main.go 项目: newgogo/Exis
func (d *Domain) Unregister(endpoint string) *js.Object {
	var p promise.Promise

	go func() {
		if err := d.coreDomain.Unregister(endpoint); err == nil {
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}
示例#5
0
文件: main.go 项目: newgogo/Exis
func (d *Domain) Call(endpoint string, args ...interface{}) *js.Object {
	var p promise.Promise

	go func() {
		if results, err := d.coreDomain.Call(endpoint, args, make([]interface{}, 0)); err == nil {
			p.Resolve(results)
		} else {
			p.Reject(err.Error())
		}
	}()

	return p.Js()
}
示例#6
0
文件: main.go 项目: newgogo/Exis
func (d *Domain) Publish(endpoint string, args ...interface{}) *js.Object {
	var p promise.Promise

	go func() {
		if err := d.coreDomain.Publish(endpoint, args); err == nil {
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}
示例#7
0
文件: main.go 项目: newgogo/Exis
func (d *Domain) Register(endpoint string, handler *js.Object) *js.Object {
	cb := core.NewID()
	var p promise.Promise

	go func() {
		if err := d.coreDomain.Register(endpoint, cb, make([]interface{}, 0)); err == nil {
			d.app.registrations[cb] = handler
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}