moontalk/server/eventloop-server-experiment/main.4th
Emil Williams e000381786
update
2024-02-03 19:15:37 +00:00

32 lines
615 B
Forth

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