예제 #1
0
func (ir *Interpreter) AsyncEval(args ...string) {
	var buf bytes.Buffer
	for _, arg := range args {
		buf.WriteString(arg)
		buf.WriteString(" ")
	}

	ir.queue <- buf.String()
	ev := C._gotk_c_new_async_eval_event(unsafe.Pointer(ir))
	C.Tcl_ThreadQueueEvent(ir.thread, ev, C.TCL_QUEUE_TAIL)
	C.Tcl_ThreadAlert(ir.thread)
}
예제 #2
0
func (ir *interpreter) run_and_wait(action func() error) (err error) {
	cond := sync.NewCond(&sync.Mutex{})
	cond.L.Lock()

	// send event
	ir.queue <- async_action{result: &err, action: action, cond: cond}
	ev := C._gotk_c_new_async_event(C.int(ir.id))
	C.Tcl_ThreadQueueEvent(ir.thread, ev, C.TCL_QUEUE_TAIL)
	C.Tcl_ThreadAlert(ir.thread)

	// wait for result
	cond.Wait()
	cond.L.Unlock()

	return
}