summary refs log tree commit diff stats
path: root/tests/js/tasync.nim
blob: 31823765195fb9f608b4cbddee4b3b734f4083f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
discard """
  output: '''
x
e
'''
"""

import asyncjs

# demonstrate forward definition
# for js
proc y(e: int): Future[string] {.async.}

proc e: int {.discardable.} =
  echo "e"
  return 2

proc x(e: int): Future[void] {.async.} =
  var s = await y(e)
  if e > 2:
    return
  echo s
  e()

proc y(e: int): Future[string] {.async.} =
  if e > 0:
    return await y(0)
  else:
    return "x"


discard x(2)
class="kt">char *(*p_error) ( void *ctx, /* context needed by send */ int err /* error code */ ); /* interface to send function */ typedef int (*p_send) ( void *ctx, /* context needed by send */ const char *data, /* pointer to buffer with data to send */ size_t count, /* number of bytes to send from buffer */ size_t *sent, /* number of bytes sent uppon return */ p_timeout tm /* timeout control */ ); /* interface to recv function */ typedef int (*p_recv) ( void *ctx, /* context needed by recv */ char *data, /* pointer to buffer where data will be writen */ size_t count, /* number of bytes to receive into buffer */ size_t *got, /* number of bytes received uppon return */ p_timeout tm /* timeout control */ ); /* IO driver definition */ typedef struct t_io_ { void *ctx; /* context needed by send/recv */ p_send send; /* send function pointer */ p_recv recv; /* receive function pointer */ p_error error; /* strerror function */ } t_io; typedef t_io *p_io; #ifndef _WIN32 #pragma GCC visibility push(hidden) #endif void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); const char *io_strerror(int err); #ifndef _WIN32 #pragma GCC visibility pop #endif #endif /* IO_H */