@@ -488,6 +488,16 @@ pub const Container = struct {
488488 _ = self ;
489489 }
490490
491+ pub fn remove (self : * const Container , peer : PeerType ) void {
492+ _ = peer ;
493+ _ = self ;
494+ }
495+
496+ pub fn setTabOrder (self : * const Container , peers : []const PeerType ) void {
497+ _ = peers ;
498+ _ = self ;
499+ }
500+
491501 pub fn move (self : * const Container , peer : PeerType , x : u32 , y : u32 ) void {
492502 _ = self ;
493503 js .setPos (peer .element , x , y );
@@ -521,31 +531,59 @@ pub const HttpResponse = struct {
521531 }
522532};
523533
524- // Execution
525-
526- fn executeStart () void {
527- const startFn = @import ("root" ).start ;
528- const ReturnType = @typeInfo (@TypeOf (startFn )).Fn .return_type .? ;
529- if (ReturnType == void ) {
530- startFn ();
531- } else {
532- startFn () catch | err | @panic (@errorName (err ));
533- }
534- }
534+ var stopExecution = false ;
535535
536- fn executeStep () void {
537- // Check for events
536+ // Temporary execution until async is added back in Zig
537+ pub fn runStep (step : shared.EventLoopStep ) bool {
538+ _ = step ;
539+ js .yield ();
538540 while (js .hasEvent ()) {
539541 const eventId = js .popEvent ();
540- if (globalWindow ) | window | {
541- if (window .child ) | child | {
542- child .processEventFn (child .object , eventId );
543- }
542+ switch (js .getEventType (eventId )) {
543+ else = > {
544+ if (globalWindow ) | window | {
545+ if (window .child ) | child | {
546+ child .processEventFn (child .object , eventId );
547+ }
548+ }
549+ },
544550 }
545551 }
546- lib .eventStep .callListeners ();
552+ return ! stopExecution ;
553+ }
554+
555+ fn executeMain () void {
556+ const mainFn = @import ("root" ).main ;
557+ const ReturnType = @typeInfo (@TypeOf (mainFn )).Fn .return_type .? ;
558+ if (ReturnType == void ) {
559+ mainFn ();
560+ } else {
561+ mainFn () catch | err | @panic (@errorName (err ));
562+ }
563+ js .stopExecution ();
564+ stopExecution = true ;
547565}
548566
567+ // Execution
568+ // TODO: reuse the old system when async is finally reimplemented in the zig compiler
569+
570+ // fn executeMain() callconv(.Async) void {
571+ // const mainFn = @import("root").main;
572+ // const ReturnType = @typeInfo(@TypeOf(mainFn)).Fn.return_type.?;
573+ // if (ReturnType == void) {
574+ // mainFn();
575+ // } else {
576+ // mainFn() catch |err| @panic(@errorName(err));
577+ // }
578+ // js.stopExecution();
579+ // }
580+
581+ // var frame: @Frame(executeMain) = undefined;
582+ // var result: void = {};
583+ // var suspending: bool = false;
584+
585+ // var resumePtr: anyframe = undefined;
586+
549587fn milliTimestamp () i64 {
550588 return @as (i64 , @intFromFloat (js .now ()));
551589}
@@ -587,11 +625,7 @@ pub const backendExport = struct {
587625
588626 const start = milliTimestamp ();
589627 while (milliTimestamp () < start + @as (i64 , @intCast (duration ))) {
590- // TODO: when zig async is restored, use suspend here
591- // suspending = true;
592- // suspend {
593- // resumePtr = @frame();
594- // }
628+ // TODO: better way to sleep like calling a jS function for sleep
595629 }
596630 return 0 ;
597631 }
@@ -633,15 +667,24 @@ pub const backendExport = struct {
633667
634668 //@breakpoint();
635669 js .stopExecution ();
670+ stopExecution = true ;
671+ while (true ) {}
636672 }
637673
638674 pub export fn _start () callconv (.C ) void {
639- executeStart ();
675+ executeMain ();
640676 }
641677
642- pub export fn _capyStep () callconv (.C ) void {
643- executeStep ();
644- }
678+ // pub export fn _start() callconv(.C) void {
679+ // _ = @asyncCall(&frame, &result, executeMain, .{});
680+ // }
681+
682+ // pub export fn _capyStep() callconv(.C) void {
683+ // if (suspending) {
684+ // suspending = false;
685+ // resume resumePtr;
686+ // }
687+ // }
645688};
646689
647690// pub fn runStep(step: shared.EventLoopStep) callconv(.Async) bool {
@@ -658,5 +701,9 @@ pub const backendExport = struct {
658701// },
659702// }
660703// }
704+ // suspending = true;
705+ // suspend {
706+ // resumePtr = @frame();
707+ // }
661708// return true;
662709// }
0 commit comments