Skip to content

Commit 9db0e0d

Browse files
committed
Initialize new go async API
1 parent ae0ac08 commit 9db0e0d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

source/ports/go_port/source/go_port.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ type callSafeWork struct {
3030
ret chan callReturnSafeWork
3131
}
3232

33+
type callSafeAsyncWork struct {
34+
function string
35+
args []interface{}
36+
ret chan callReturnSafeWork
37+
}
38+
3339
const PtrSizeInBytes = (32 << uintptr(^uintptr(0)>>63)) >> 3
3440

3541
var queue = make(chan interface{}, 1)
@@ -89,6 +95,11 @@ func Initialize() error {
8995
value, err := CallUnsafe(v.function, v.args...)
9096
v.ret <- callReturnSafeWork{value, err}
9197
}
98+
case callSafeAsyncWork:
99+
{
100+
value, err := CallAwaitUnsafe(v.function, v.args...)
101+
v.ret <- callReturnSafeWork{value, err}
102+
}
92103
}
93104
wg.Done()
94105
}
@@ -185,7 +196,8 @@ func CallAwaitUnsafe(function string, args ...interface{}) (interface{}, error)
185196
}
186197
})()
187198

188-
ret := C.metacallfv(cFunc, (*unsafe.Pointer)(cArgs))
199+
//ret := C.metacallfv(cFunc, (*unsafe.Pointer)(cArgs))
200+
ret := C.metacallfv_await(cFunc, (*unsafe.Pointer)(cArgs))
189201

190202
if ret != nil {
191203
defer C.metacall_value_destroy(ret)
@@ -318,6 +330,22 @@ func Call(function string, args ...interface{}) (interface{}, error) {
318330
return result.value, result.err
319331
}
320332

333+
// CallAsync sends asynchronous work and blocks until it's processed
334+
func CallAsync(function string, args ...interface{}) (interface{}, error) {
335+
ret := make(chan callReturnSafeWork, 1)
336+
w := callSafeAsyncWork{
337+
function: function,
338+
args: args,
339+
ret: ret,
340+
}
341+
wg.Add(1)
342+
queue <- w
343+
344+
result := <-ret
345+
346+
return result.value, result.err
347+
}
348+
321349
func DestroyUnsafe() {
322350
C.metacall_destroy()
323351
}

0 commit comments

Comments
 (0)