moontalk/server/eventloop-server-experiment/main.4th

32 lines
615 B
Plaintext
Raw Normal View History

2024-02-03 12:37:01 -05:00
require check-gforth.4th
require eventloop.4th
require event-constants.4th
require server.4th
2024-02-03 14:15:37 -05:00
variable clcounter
0 clcounter !
: handle-command-line? ( -- flag )
clcounter @ 10 >= dup IF
0 clcounter !
ELSE
1 clcounter +!
THEN ;
2024-02-03 12:37:01 -05:00
: custom-eventloop ( -- )
BEGIN
2024-02-03 14:15:37 -05:00
handle-command-line? IF
0 EVENT_COMMANDLINE events.enqueue
THEN
2024-02-03 12:37:01 -05:00
eventloop.has-events? IF
eventloop.dispatch
ELSE
server-idle? IF
2024-02-03 14:15:37 -05:00
1 ms false server-idle!
2024-02-03 12:37:01 -05:00
THEN
0 0 events.enqueue eventloop.dispatch
THEN
AGAIN ;
2024-02-03 14:15:37 -05:00
: main ( -- ) ['] custom-eventloop catch close-server throw ;
main