Skip to content

Commit a8cf0c9

Browse files
AtkinsSJawesomekling
authored andcommitted
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:
1 parent a15d44f commit a8cf0c9

File tree

20 files changed

+42
-36
lines changed

20 files changed

+42
-36
lines changed

Tests/LibCore/TestLibCoreDeferredInvoke.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
TEST_CASE(deferred_invoke)
1313
{
1414
Core::EventLoop event_loop;
15-
auto reaper = Core::Timer::create_single_shot(250, [] {
15+
auto reaper = MUST(Core::Timer::create_single_shot(250, [] {
1616
warnln("I waited for the deferred_invoke to happen, but it never did!");
1717
VERIFY_NOT_REACHED();
18-
});
18+
}));
1919

2020
Core::deferred_invoke([&event_loop] {
2121
event_loop.quit(0);

Tests/LibCore/TestLibCoreFileWatcher.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ TEST_CASE(file_watcher_child_events)
3939
event_count++;
4040
};
4141

42-
auto timer1 = Core::Timer::create_single_shot(500, [&] {
42+
auto timer1 = MUST(Core::Timer::create_single_shot(500, [&] {
4343
int rc = creat("/tmp/testfile", 0777);
4444
EXPECT_NE(rc, -1);
45-
});
45+
}));
4646
timer1->start();
4747

48-
auto timer2 = Core::Timer::create_single_shot(1000, [&] {
48+
auto timer2 = MUST(Core::Timer::create_single_shot(1000, [&] {
4949
int rc = unlink("/tmp/testfile");
5050
EXPECT_NE(rc, -1);
51-
});
51+
}));
5252
timer2->start();
5353

54-
auto catchall_timer = Core::Timer::create_single_shot(2000, [&] {
54+
auto catchall_timer = MUST(Core::Timer::create_single_shot(2000, [&] {
5555
VERIFY_NOT_REACHED();
56-
});
56+
}));
5757
catchall_timer->start();
5858

5959
event_loop.exec();

Userland/Applications/Assistant/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
233233
GUI::Application::the()->quit();
234234
};
235235

236-
auto update_ui_timer = Core::Timer::create_single_shot(10, [&] {
236+
auto update_ui_timer = TRY(Core::Timer::create_single_shot(10, [&] {
237237
results_container.remove_all_children();
238238
results_layout.set_margins(app_state.visible_result_count ? GUI::Margins { 4, 0, 0, 0 } : GUI::Margins { 0 });
239239

@@ -251,7 +251,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
251251

252252
mark_selected_item();
253253
Core::deferred_invoke([&] { window->resize(GUI::Desktop::the().rect().width() / 3, {}); });
254-
});
254+
}));
255255

256256
db.on_new_results = [&](auto results) {
257257
if (results.is_empty())

Userland/Applications/PixelPaint/Filters/Filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Filter::Filter(ImageEditor* editor)
1717
, m_update_timer(Core::Timer::create_single_shot(100, [&] {
1818
if (on_settings_change)
1919
on_settings_change();
20-
}))
20+
}).release_value_but_fixme_should_propagate_errors())
2121
{
2222
m_update_timer->set_active(false);
2323
}

Userland/Games/Hearts/Game.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Game::Game()
2828
m_delay_timer = Core::Timer::create_single_shot(0, [this] {
2929
dbgln_if(HEARTS_DEBUG, "Continuing game after delay...");
3030
advance_game();
31-
});
31+
}).release_value_but_fixme_should_propagate_errors();
3232

3333
constexpr int card_overlap = 20;
3434
constexpr int outer_border_size = 15;
@@ -155,7 +155,7 @@ void Game::show_score_card(bool game_over)
155155
if (!m_players[0].is_human) {
156156
close_timer = Core::Timer::create_single_shot(2000, [&] {
157157
score_dialog->close();
158-
});
158+
}).release_value_but_fixme_should_propagate_errors();
159159
close_timer->start();
160160
}
161161

@@ -236,7 +236,7 @@ void Game::start_animation(NonnullRefPtrVector<Card> cards, Gfx::IntPoint end, F
236236
m_animation_delay_timer = Core::Timer::create_single_shot(initial_delay_ms, [&] {
237237
m_animation_playing = true;
238238
start_timer(10);
239-
});
239+
}).release_value_but_fixme_should_propagate_errors();
240240
m_animation_delay_timer->start();
241241
}
242242

Userland/Games/MasterWord/WordGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ REGISTER_WIDGET(MasterWord, WordGame)
2525
namespace MasterWord {
2626

2727
WordGame::WordGame()
28-
: m_clear_message_timer(Core::Timer::create_single_shot(5000, [this] { clear_message(); }))
28+
: m_clear_message_timer(Core::Timer::create_single_shot(5000, [this] { clear_message(); }).release_value_but_fixme_should_propagate_errors())
2929
{
3030
read_words();
3131
m_num_letters = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5);

Userland/Libraries/LibCore/Debounce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ auto debounce(TFunction function, int timeout)
2020
timer->stop();
2121
timer->on_timeout = move(apply_function);
2222
} else {
23-
timer = Core::Timer::create_single_shot(timeout, move(apply_function));
23+
timer = Core::Timer::create_single_shot(timeout, move(apply_function)).release_value_but_fixme_should_propagate_errors();
2424
}
2525
timer->start();
2626
};

Userland/Libraries/LibCore/Timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class Timer final : public Object {
2222
timer->stop();
2323
return timer;
2424
}
25-
static NonnullRefPtr<Timer> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
25+
static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
2626
{
27-
auto timer = adopt_ref(*new Timer(interval_ms, move(timeout_handler), parent));
27+
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
2828
timer->set_single_shot(true);
2929
timer->stop();
3030
return timer;

Userland/Libraries/LibGUI/Application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ Application::Application(int argc, char** argv, Core::EventLoop::MakeInspectable
9595

9696
m_tooltip_show_timer = Core::Timer::create_single_shot(700, [this] {
9797
request_tooltip_show();
98-
});
98+
}).release_value_but_fixme_should_propagate_errors();
9999

100100
m_tooltip_hide_timer = Core::Timer::create_single_shot(50, [this] {
101101
tooltip_hide_timer_did_fire();
102-
});
102+
}).release_value_but_fixme_should_propagate_errors();
103103
}
104104

105105
static bool s_in_teardown;

Userland/Libraries/LibGUI/TextEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ void TextEditor::set_should_autocomplete_automatically(bool value)
22652265
m_autocomplete_timer = Core::Timer::create_single_shot(m_automatic_autocomplete_delay_ms, [this] {
22662266
if (m_autocomplete_box && !m_autocomplete_box->is_visible())
22672267
try_show_autocomplete(UserRequestedAutocomplete::No);
2268-
});
2268+
}).release_value_but_fixme_should_propagate_errors();
22692269
return;
22702270
}
22712271

0 commit comments

Comments
 (0)