File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
source/ports/go_port/source Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ This project implements a wrapper of MetaCall API for Go.
1111export function concat(left : string , right : string ): string {
1212 return left + right ;
1313}
14+ export async function sum(a : number , b : number ): Promise <number > {
15+ return a + b ;
16+ }
1417```
1518
1619` main.go ` :
@@ -48,6 +51,31 @@ func main() {
4851 if str , ok := ret.(string ); ok {
4952 fmt.Println (str)
5053 }
54+
55+ // Calling async function in typescript
56+ var sum int
57+ var wg sync.WaitGroup
58+ wg.Add (1 )
59+ _ , err := metacall.Await (" sum" ,
60+ func (value interface {}, ctx interface {}) interface {} {
61+ log.Println (" from resolve callback " , value)
62+ sum = value
63+ wg.Done ()
64+ return nil
65+ },
66+ func (value interface {}, ctx interface {}) interface {} {
67+ log.Println (" from reject callback " , value)
68+ sum = value
69+ wg.Done ()
70+ return nil
71+ },
72+ nil ,
73+ 10 , 20 )
74+ if err != nil {
75+ fmt.Println (err)
76+ return
77+ }
78+ fmt.Println (sum)
5179}
5280```
5381
You can’t perform that action at this time.
0 commit comments