Skip to content

Add examples for serial gate. - #18

Merged
lucteo merged 4 commits into
mainfrom
examples
Sep 28, 2026
Merged

lucteo merged 4 commits into
mainfrom
examples

Conversation

@lucteo

@lucteo lucteo commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

pre-commit

[pre-commit] reported by reviewdog 🐶

using beman::gates::serial_gate;


[pre-commit] reported by reviewdog 🐶

using namespace beman::execution;


[pre-commit] reported by reviewdog 🐶


[pre-commit] reported by reviewdog 🐶

std::print("saving document: {}\n", d.data);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return just();


[pre-commit] reported by reviewdog 🐶


[pre-commit] reported by reviewdog 🐶

auto work
= just(std::move(d))
| let_value(save_async);


[pre-commit] reported by reviewdog 🐶

auto protected_work =
within(gate.try_acquire(), std::move(work)); // UPDATE: speculative execution


[pre-commit] reported by reviewdog 🐶

// NEW: ignore the error
auto handle_error
= std::move(protected_work)
| upon_error([](busy_error) noexcept {});


[pre-commit] reported by reviewdog 🐶

spawn(std::move(handle_error), scope.get_token());


[pre-commit] reported by reviewdog 🐶

constexpr auto N = 10;
std::thread threads[N];
for (int i = 0; i < N; ++i) {
threads[i] = std::thread([i]() {
trigger_save(document{i});
});
}
for (int i = 0; i < N; ++i) {
threads[i].join();
}
sync_wait(scope.join());
return 0;
}


[pre-commit] reported by reviewdog 🐶


[pre-commit] reported by reviewdog 🐶

void insert(record r) {
std::print("insert called: {}\n", r.data);
}


[pre-commit] reported by reviewdog 🐶

void perform_logging_after_update(record r) noexcept {
std::print("Logging after update: {}\n", r.data);
}


[pre-commit] reported by reviewdog 🐶

serial_gate cache_gate;
cache c;


[pre-commit] reported by reviewdog 🐶

auto update
= just(std::move(r))
| then([&](record r) noexcept {
c.insert(r);
return r;
});
auto protected_update =
within(cache_gate.acquire(), std::move(update));
// NEW
auto with_logging
= std::move(protected_update)
| then(perform_logging_after_update);
spawn(std::move(with_logging), scope.get_token());


[pre-commit] reported by reviewdog 🐶

constexpr auto N = 20;
std::thread threads[N];
for (int i = 0; i < N; ++i) {
threads[i] = std::thread([i]() {
on_record({i});
});
}
for (int i = 0; i < N; ++i) {
threads[i].join();
}
sync_wait(scope.join());
return 0;
}

@coveralls

coveralls commented Sep 28, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 36473201770

Coverage decreased (-0.5%) to 98.104%

Details

  • Coverage decreased (-0.5%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 1 coverage regression across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
include/beman/gates/detail/synchronized_value.hpp 1 87.5%

Coverage Stats

Coverage Status
Relevant Lines: 211
Covered Lines: 207
Line Coverage: 98.1%
Coverage Strength: 129.8 hits per line

💛 - Coveralls

@lucteo
lucteo merged commit c505fdf into main Sep 28, 2026
62 checks passed
@lucteo
lucteo deleted the examples branch September 28, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants