Update README.md with async example
Add an example to call an async function in typescript using Await function and catching the resolved value of promise in callback
@@ -11,6 +11,9 @@ This project implements a wrapper of MetaCall API for Go.
export function concat(left: string, right: string): string {
return left + right;
}
+export async function sum(a: number, b: number): Promise<number> {
+ return a + b;
+}
```
`main.go`:
@@ -48,6 +51,29 @@ func main() {
if str, ok := ret.(string); ok {
fmt.Println(str)
}
+
+ // Calling async function in typescript
+ var sum int
+ _, err := metacall.Await("sum",
+ func(value interface{}, ctx interface{}) interface{} {
+ log.Println("from resolve callback ", value)
+ sum = value
+ wg.Done()
+ return nil
+ },
+ func(value interface{}, ctx interface{}) interface{} {
+ log.Println("from reject callback ", value)
+ sum = value
+ wg.Done()
+ return nil
+ },
+ nil,
+ 10, 20)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ fmt.Println(sum)
}
```
