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

57 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-02-17 13:26:14 -05:00
require util.4th
require torcontrol-constants.4th
require configuration.4th
require stdout-hook.4th
2024-02-03 12:37:01 -05:00
require check-gforth.4th
require eventloop.4th
require event-constants.4th
require server.4th
2024-02-17 13:26:14 -05:00
\ TODO: integrate generic timed event handling into the event loop?
0 variable! clcounter
2024-02-03 14:15:37 -05:00
: handle-command-line? ( -- flag )
clcounter @ 10 >= dup IF
0 clcounter !
ELSE
1 clcounter +!
THEN ;
2024-02-17 13:26:14 -05:00
0 variable! dostimer
: handle-dos? ( -- flag )
0 time dup dostimer @ > IF
DOS_UPDATE_INTERVAL + dostimer !
true
ELSE
drop false
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-17 13:26:14 -05:00
handle-dos? IF
dos-update
THEN
2024-02-03 12:37:01 -05:00
eventloop.has-events? IF
eventloop.dispatch
ELSE
server-idle? IF
2024-02-17 13:26:14 -05:00
10 ms false server-idle!
2024-02-03 12:37:01 -05:00
THEN
0 0 events.enqueue eventloop.dispatch
THEN
AGAIN ;
2024-02-17 13:26:14 -05:00
: main ( -- )
logger.open
['] custom-eventloop catch close-server throw
logger.close ;
\ : main ( -- )
\ logger.open
\ custom-eventloop close-server
\ logger.close ;
2024-02-03 14:15:37 -05:00
main