# Fair. # Question, because I don't quite get what's going on here and this is closure # related: # Owlkettle has a proc to add timeouts proc addGlobalTimeout(interval: int, fn: TimeoutProc, priority: int = 200): EventDescriptor = let (call, data, destroy) = allocCallback(fn) result = EventDescriptor(g_timeout_add_full( cint(priority), cuint(interval), call, data, destroy )) # I'm looking at this and I have questionmarks over my head on how I would use # that to replace proc addServerListener(app: Viewable, hub: ChannelHub[string, string], priority: int = 200) = proc listener(cell: pointer): cbool {.cdecl.} = let data = cast[ptr ListenerData](cell)[] if data.hub.hasServerMsg(): discard data.app.redraw() const KEEP_LISTENER_ACTIVE = true return KEEP_LISTENER_ACTIVE.cbool let data = allocSharedCell(ListenerData(hub: hub, app: app)) # discard g_idle_add_full(priority.cint, listener, data, nil) const MESSAGE_CHECK_INTERVAL_MS = 5.cuint discard g_timeout_add_full(priority.cint, MESSAGE_CHECK_INTERVAL_MS, listener, data, nil)