Skip to content

Commit 09634eb

Browse files
danbevtinglou
authored andcommitted
server : use lambda instead of std::bind (ggml-org#11507)
This commit replaces the two usages of `std::bind` in favor of lambdas for the callback functions for `callback_new_task` and `callback_update_slots`. The motivation for this changes is consistency with the rest of the code in server.cpp (lambdas are used for all other callbacks/handlers). Also lambdas are more readable (perhaps this is subjective) but also they are recommended over `std::bind` in modern C++. Ref: https://github.com/LithoCoders/dailycpp/blob/master/EffectiveModernC%2B%2B/chapter6/Item34_Prefer_lambdas_to_std::bind.md
1 parent e729572 commit 09634eb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/server/server.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,11 +4387,13 @@ int main(int argc, char ** argv) {
43874387
ctx_server.chat_templates.template_default->source().c_str(),
43884388
common_chat_format_example(*ctx_server.chat_templates.template_default, ctx_server.params_base.use_jinja).c_str());
43894389

4390-
ctx_server.queue_tasks.on_new_task(std::bind(
4391-
&server_context::process_single_task, &ctx_server, std::placeholders::_1));
4390+
ctx_server.queue_tasks.on_new_task([&ctx_server](const server_task & task) {
4391+
ctx_server.process_single_task(task);
4392+
});
43924393

4393-
ctx_server.queue_tasks.on_update_slots(std::bind(
4394-
&server_context::update_slots, &ctx_server));
4394+
ctx_server.queue_tasks.on_update_slots([&ctx_server]() {
4395+
ctx_server.update_slots();
4396+
});
43954397

43964398
shutdown_handler = [&](int) {
43974399
ctx_server.queue_tasks.terminate();

0 commit comments

Comments
 (0)