Debian Codegraph @

plugin/gtk3/mainloop.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 module Mainloop
4 TICK_MAX = 20
5 TICK_MIN = 2
6
7 def mainloop
8 @exit_flag = false
9 catch(:__exit_mikutter) do
10 tick = TICK_MAX
11 loop do
12 if tick > TICK_MIN
13 tick -= 1
14 end
15 if Gtk.events_pending?
16 tick = TICK_MAX + 1
17 Gtk.main_iteration
18 throw :__exit_mikutter if @exit_flag || Gtk.exception
19 end
20 unless Delayer.empty?
21 tick = TICK_MAX + 1
22 Delayer.run_once
23 throw :__exit_mikutter if @exit_flag || Gtk.exception
24 end
25 sleep(1.0 / tick) if tick <= TICK_MAX
26 end
27 end
28 rescue Interrupt, SystemExit => exception
29 raise exception
30 rescue Exception => exception # rubocop:disable Lint/RescueException
31 Gtk.exception = exception
32 ensure
33 SerialThreadGroup.force_exit!
34 end
35
36 def exception_filter(exc)
37 Gtk.exception || exc
38 end
39
40 def reserve_exit
41 @exit_flag = true
42 end
43
44 def exit!
45 throw(:__exit_mikutter)
46 end
47 end