Skip to content

Commit

Permalink
Used Wait Function in pause.cpp (#19)
Browse files Browse the repository at this point in the history
* Used Wait Function in pause.cpp

* updated README.md

---------

Co-authored-by: Colin S <[email protected]>
Co-authored-by: John R Patek Sr <[email protected]>
  • Loading branch information
3 people authored Jan 5, 2025
1 parent a91a24e commit 02c06f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
19 changes: 4 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,16 @@ Basic SigFn usage in C++. It is copied from `pause.cpp` in the
```c++
#include <sigfn.hpp>
#include <iostream>
#include <thread>
int main(int argc, const char **argv)
{
bool loop;
// set callback for SIGINT
sigfn::handle(SIGINT, [&](int signum) {
std::cout << std::endl << "Received signal: " << signum << std::endl;
loop = false;
});
// notify user that the program is "paused"
std::cout << "Paused. Press Ctrl+C to exit." << std::endl;
// sleep loop until we receive the signal
loop = true;
while(loop)
{
// sleep for 100ms
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
sigfn::wait({SIGINT});
std::cout << std::endl << "Received signal: SIGINT" << std::endl;
return 0;
}
```
19 changes: 4 additions & 15 deletions examples/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@

#include <sigfn.hpp>
#include <iostream>
#include <thread>

int main(int argc, const char **argv)
{
bool loop;
// set callback for SIGINT
sigfn::handle(SIGINT, [&](int signum) {
std::cout << std::endl << "Received signal: " << signum << std::endl;
loop = false;
});

// notify user that the program is "paused"
std::cout << "Paused. Press Ctrl+C to exit." << std::endl;

// sleep loop until we receive the signal
loop = true;
while(loop)
{
// sleep for 100ms
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
sigfn::wait({SIGINT});

std::cout << std::endl << "Received signal: SIGINT" << std::endl;

return 0;
}

0 comments on commit 02c06f1

Please sign in to comment.