mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:42:43 +00:00 
			
		
		
		
	LibCore+Userland: Make Core::Timer::create_single_shot() return ErrorOr
clang-format sure has some interesting opinions about where to put a method call that comes after a lambda. :thonk:
This commit is contained in:
		
							parent
							
								
									a15d44f019
								
							
						
					
					
						commit
						a8cf0c9371
					
				
					 20 changed files with 42 additions and 36 deletions
				
			
		|  | @ -12,10 +12,10 @@ | |||
| TEST_CASE(deferred_invoke) | ||||
| { | ||||
|     Core::EventLoop event_loop; | ||||
|     auto reaper = Core::Timer::create_single_shot(250, [] { | ||||
|     auto reaper = MUST(Core::Timer::create_single_shot(250, [] { | ||||
|         warnln("I waited for the deferred_invoke to happen, but it never did!"); | ||||
|         VERIFY_NOT_REACHED(); | ||||
|     }); | ||||
|     })); | ||||
| 
 | ||||
|     Core::deferred_invoke([&event_loop] { | ||||
|         event_loop.quit(0); | ||||
|  |  | |||
|  | @ -39,21 +39,21 @@ TEST_CASE(file_watcher_child_events) | |||
|         event_count++; | ||||
|     }; | ||||
| 
 | ||||
|     auto timer1 = Core::Timer::create_single_shot(500, [&] { | ||||
|     auto timer1 = MUST(Core::Timer::create_single_shot(500, [&] { | ||||
|         int rc = creat("/tmp/testfile", 0777); | ||||
|         EXPECT_NE(rc, -1); | ||||
|     }); | ||||
|     })); | ||||
|     timer1->start(); | ||||
| 
 | ||||
|     auto timer2 = Core::Timer::create_single_shot(1000, [&] { | ||||
|     auto timer2 = MUST(Core::Timer::create_single_shot(1000, [&] { | ||||
|         int rc = unlink("/tmp/testfile"); | ||||
|         EXPECT_NE(rc, -1); | ||||
|     }); | ||||
|     })); | ||||
|     timer2->start(); | ||||
| 
 | ||||
|     auto catchall_timer = Core::Timer::create_single_shot(2000, [&] { | ||||
|     auto catchall_timer = MUST(Core::Timer::create_single_shot(2000, [&] { | ||||
|         VERIFY_NOT_REACHED(); | ||||
|     }); | ||||
|     })); | ||||
|     catchall_timer->start(); | ||||
| 
 | ||||
|     event_loop.exec(); | ||||
|  |  | |||
|  | @ -233,7 +233,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|             GUI::Application::the()->quit(); | ||||
|     }; | ||||
| 
 | ||||
|     auto update_ui_timer = Core::Timer::create_single_shot(10, [&] { | ||||
|     auto update_ui_timer = TRY(Core::Timer::create_single_shot(10, [&] { | ||||
|         results_container.remove_all_children(); | ||||
|         results_layout.set_margins(app_state.visible_result_count ? GUI::Margins { 4, 0, 0, 0 } : GUI::Margins { 0 }); | ||||
| 
 | ||||
|  | @ -251,7 +251,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
| 
 | ||||
|         mark_selected_item(); | ||||
|         Core::deferred_invoke([&] { window->resize(GUI::Desktop::the().rect().width() / 3, {}); }); | ||||
|     }); | ||||
|     })); | ||||
| 
 | ||||
|     db.on_new_results = [&](auto results) { | ||||
|         if (results.is_empty()) | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ Filter::Filter(ImageEditor* editor) | |||
|     , m_update_timer(Core::Timer::create_single_shot(100, [&] { | ||||
|         if (on_settings_change) | ||||
|             on_settings_change(); | ||||
|     })) | ||||
|     }).release_value_but_fixme_should_propagate_errors()) | ||||
| { | ||||
|     m_update_timer->set_active(false); | ||||
| } | ||||
|  |  | |||
|  | @ -28,7 +28,7 @@ Game::Game() | |||
|     m_delay_timer = Core::Timer::create_single_shot(0, [this] { | ||||
|         dbgln_if(HEARTS_DEBUG, "Continuing game after delay..."); | ||||
|         advance_game(); | ||||
|     }); | ||||
|     }).release_value_but_fixme_should_propagate_errors(); | ||||
| 
 | ||||
|     constexpr int card_overlap = 20; | ||||
|     constexpr int outer_border_size = 15; | ||||
|  | @ -155,7 +155,7 @@ void Game::show_score_card(bool game_over) | |||
|     if (!m_players[0].is_human) { | ||||
|         close_timer = Core::Timer::create_single_shot(2000, [&] { | ||||
|             score_dialog->close(); | ||||
|         }); | ||||
|         }).release_value_but_fixme_should_propagate_errors(); | ||||
|         close_timer->start(); | ||||
|     } | ||||
| 
 | ||||
|  | @ -236,7 +236,7 @@ void Game::start_animation(NonnullRefPtrVector<Card> cards, Gfx::IntPoint end, F | |||
|     m_animation_delay_timer = Core::Timer::create_single_shot(initial_delay_ms, [&] { | ||||
|         m_animation_playing = true; | ||||
|         start_timer(10); | ||||
|     }); | ||||
|     }).release_value_but_fixme_should_propagate_errors(); | ||||
|     m_animation_delay_timer->start(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ REGISTER_WIDGET(MasterWord, WordGame) | |||
| namespace MasterWord { | ||||
| 
 | ||||
| WordGame::WordGame() | ||||
|     : m_clear_message_timer(Core::Timer::create_single_shot(5000, [this] { clear_message(); })) | ||||
|     : m_clear_message_timer(Core::Timer::create_single_shot(5000, [this] { clear_message(); }).release_value_but_fixme_should_propagate_errors()) | ||||
| { | ||||
|     read_words(); | ||||
|     m_num_letters = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5); | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ auto debounce(TFunction function, int timeout) | |||
|             timer->stop(); | ||||
|             timer->on_timeout = move(apply_function); | ||||
|         } else { | ||||
|             timer = Core::Timer::create_single_shot(timeout, move(apply_function)); | ||||
|             timer = Core::Timer::create_single_shot(timeout, move(apply_function)).release_value_but_fixme_should_propagate_errors(); | ||||
|         } | ||||
|         timer->start(); | ||||
|     }; | ||||
|  |  | |||
|  | @ -22,9 +22,9 @@ public: | |||
|         timer->stop(); | ||||
|         return timer; | ||||
|     } | ||||
|     static NonnullRefPtr<Timer> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr) | ||||
|     static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr) | ||||
|     { | ||||
|         auto timer = adopt_ref(*new Timer(interval_ms, move(timeout_handler), parent)); | ||||
|         auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent))); | ||||
|         timer->set_single_shot(true); | ||||
|         timer->stop(); | ||||
|         return timer; | ||||
|  |  | |||
|  | @ -95,11 +95,11 @@ Application::Application(int argc, char** argv, Core::EventLoop::MakeInspectable | |||
| 
 | ||||
|     m_tooltip_show_timer = Core::Timer::create_single_shot(700, [this] { | ||||
|         request_tooltip_show(); | ||||
|     }); | ||||
|     }).release_value_but_fixme_should_propagate_errors(); | ||||
| 
 | ||||
|     m_tooltip_hide_timer = Core::Timer::create_single_shot(50, [this] { | ||||
|         tooltip_hide_timer_did_fire(); | ||||
|     }); | ||||
|     }).release_value_but_fixme_should_propagate_errors(); | ||||
| } | ||||
| 
 | ||||
| static bool s_in_teardown; | ||||
|  |  | |||
|  | @ -2265,7 +2265,7 @@ void TextEditor::set_should_autocomplete_automatically(bool value) | |||
|         m_autocomplete_timer = Core::Timer::create_single_shot(m_automatic_autocomplete_delay_ms, [this] { | ||||
|             if (m_autocomplete_box && !m_autocomplete_box->is_visible()) | ||||
|                 try_show_autocomplete(UserRequestedAutocomplete::No); | ||||
|         }); | ||||
|         }).release_value_but_fixme_should_propagate_errors(); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ ConnectionBase::ConnectionBase(IPC::Stub& local_stub, NonnullOwnPtr<Core::Stream | |||
|     , m_local_endpoint_magic(local_endpoint_magic) | ||||
|     , m_deferred_invoker(make<CoreEventLoopDeferredInvoker>()) | ||||
| { | ||||
|     m_responsiveness_timer = Core::Timer::create_single_shot(3000, [this] { may_have_become_unresponsive(); }); | ||||
|     m_responsiveness_timer = Core::Timer::create_single_shot(3000, [this] { may_have_become_unresponsive(); }).release_value_but_fixme_should_propagate_errors(); | ||||
| } | ||||
| 
 | ||||
| void ConnectionBase::set_deferred_invoker(NonnullOwnPtr<DeferredInvoker> deferred_invoker) | ||||
|  |  | |||
|  | @ -144,7 +144,7 @@ void TLSv12::setup_connection() | |||
|                     // Extend the timer, we are too slow.
 | ||||
|                     m_handshake_timeout_timer->restart(m_max_wait_time_for_handshake_in_seconds * 1000); | ||||
|                 } | ||||
|             }); | ||||
|             }).release_value_but_fixme_should_propagate_errors(); | ||||
|         auto packet = build_hello(); | ||||
|         write_packet(packet); | ||||
|         write_into_socket(); | ||||
|  |  | |||
|  | @ -177,7 +177,8 @@ void Mixer::request_setting_sync() | |||
|                 if (auto result = m_config->sync(); result.is_error()) | ||||
|                     dbgln("Failed to write audio mixer config: {}", result.error()); | ||||
|             }, | ||||
|             this); | ||||
|             this) | ||||
|                                    .release_value_but_fixme_should_propagate_errors(); | ||||
|         m_config_write_timer->start(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -76,7 +76,7 @@ static Core::ConfigFile& ensure_domain_config(DeprecatedString const& domain) | |||
| 
 | ||||
| ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> client_socket, int client_id) | ||||
|     : IPC::ConnectionFromClient<ConfigClientEndpoint, ConfigServerEndpoint>(*this, move(client_socket), client_id) | ||||
|     , m_sync_timer(Core::Timer::create_single_shot(s_disk_sync_delay_ms, [this]() { sync_dirty_domains_to_disk(); })) | ||||
|     , m_sync_timer(Core::Timer::create_single_shot(s_disk_sync_delay_ms, [this]() { sync_dirty_domains_to_disk(); }).release_value_but_fixme_should_propagate_errors()) | ||||
| { | ||||
|     s_connections.set(client_id, *this); | ||||
| } | ||||
|  |  | |||
|  | @ -261,7 +261,8 @@ void DHCPv4Client::handle_ack(DHCPv4Packet const& packet, ParsedDHCPv4Options co | |||
|             transaction->has_ip = false; | ||||
|             dhcp_discover(interface); | ||||
|         }, | ||||
|         this); | ||||
|         this) | ||||
|         .release_value_but_fixme_should_propagate_errors(); | ||||
| 
 | ||||
|     Optional<IPv4Address> gateway; | ||||
|     if (auto routers = options.get_many<IPv4Address>(DHCPOption::Router, 1); !routers.is_empty()) | ||||
|  | @ -288,7 +289,8 @@ void DHCPv4Client::handle_nak(DHCPv4Packet const& packet, ParsedDHCPv4Options co | |||
|         [this, iface = InterfaceDescriptor { iface }] { | ||||
|             dhcp_discover(iface); | ||||
|         }, | ||||
|         this); | ||||
|         this) | ||||
|         .release_value_but_fixme_should_propagate_errors(); | ||||
| } | ||||
| 
 | ||||
| void DHCPv4Client::process_incoming(DHCPv4Packet const& packet) | ||||
|  |  | |||
|  | @ -203,7 +203,7 @@ decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job, | |||
|         sockets_for_url.append(make<ConnectionType>( | ||||
|             socket_result.release_value(), | ||||
|             typename ConnectionType::QueueType {}, | ||||
|             Core::Timer::create_single_shot(ConnectionKeepAliveTimeMilliseconds, nullptr))); | ||||
|             Core::Timer::create_single_shot(ConnectionKeepAliveTimeMilliseconds, nullptr).release_value_but_fixme_should_propagate_errors())); | ||||
|         sockets_for_url.last().proxy = move(proxy); | ||||
|         did_add_new_connection = true; | ||||
|     } | ||||
|  |  | |||
|  | @ -55,14 +55,16 @@ Compositor::Compositor() | |||
|         [this] { | ||||
|             compose(); | ||||
|         }, | ||||
|         this); | ||||
|         this) | ||||
|                           .release_value_but_fixme_should_propagate_errors(); | ||||
| 
 | ||||
|     m_immediate_compose_timer = Core::Timer::create_single_shot( | ||||
|         0, | ||||
|         [this] { | ||||
|             compose(); | ||||
|         }, | ||||
|         this); | ||||
|         this) | ||||
|                                     .release_value_but_fixme_should_propagate_errors(); | ||||
| 
 | ||||
|     init_bitmaps(); | ||||
| } | ||||
|  | @ -1589,7 +1591,8 @@ void Compositor::start_window_stack_switch_overlay_timer() | |||
|         [this] { | ||||
|             remove_window_stack_switch_overlays(); | ||||
|         }, | ||||
|         this); | ||||
|         this) | ||||
|                                        .release_value_but_fixme_should_propagate_errors(); | ||||
|     m_stack_switch_overlay_timer->start(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -240,7 +240,7 @@ void ConnectionFromClient::flash_menubar_menu(i32 window_id, i32 menu_id) | |||
|                 return; | ||||
|             weak_window->menubar().flash_menu(nullptr); | ||||
|             weak_window->frame().invalidate_menubar(); | ||||
|         }); | ||||
|         }).release_value_but_fixme_should_propagate_errors(); | ||||
|         m_flashed_menu_timer->start(); | ||||
|     } else if (m_flashed_menu_timer) { | ||||
|         m_flashed_menu_timer->restart(); | ||||
|  | @ -1134,7 +1134,7 @@ void ConnectionFromClient::may_have_become_unresponsive() | |||
|     async_ping(); | ||||
|     m_ping_timer = Core::Timer::create_single_shot(1000, [this] { | ||||
|         set_unresponsive(true); | ||||
|     }); | ||||
|     }).release_value_but_fixme_should_propagate_errors(); | ||||
|     m_ping_timer->start(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1857,9 +1857,9 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s | |||
|         true); | ||||
| 
 | ||||
|     Vector<Line::CompletionSuggestion> suggestions; | ||||
|     auto timer = Core::Timer::create_single_shot(300, [&] { | ||||
|     auto timer = TRY(Core::Timer::create_single_shot(300, [&] { | ||||
|         Core::EventLoop::current().quit(1); | ||||
|     }); | ||||
|     })); | ||||
|     timer->start(); | ||||
| 
 | ||||
|     // Restrict the process to effectively readonly access to the FS.
 | ||||
|  |  | |||
|  | @ -700,7 +700,7 @@ static void load_page_for_screenshot_and_exit(HeadlessBrowserPageClient& page_cl | |||
|             MUST(output_file->write(image_buffer.bytes())); | ||||
| 
 | ||||
|             exit(0); | ||||
|         }); | ||||
|         }).release_value_but_fixme_should_propagate_errors(); | ||||
| 
 | ||||
|     timer->start(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins