Skip to content
Snippets Groups Projects
FutureCallbackTest.cpp 598 B
Newer Older
  • Learn to ignore specific revisions
  • // SPDX-License-Identifier: LGPL-3.0-or-later
    // Copyright © 2020-2021 Florian Fischer
    #include <cassert>	// for assert
    #include <cerrno>		// for ETIME
    #include <cstdint>	// for int32_t
    
    #include "BinaryPrivateSemaphore.hpp"
    #include "io/Future.hpp"	// for AlarmFuture
    
    using emper::io::AlarmFuture;
    using emper::io::Future;
    
    void emperTest() {
    
    	AlarmFuture::Timespec ts = {.tv_sec = 1, .tv_nsec = 0};
    
    	AlarmFuture alarm(ts);
    	BPS bps;
    
    
    	alarm.setCallback([&bps](int32_t res) {
    		assert(res == -ETIME);
    		bps.signal();
    	});
    
    	alarm.submit();
    
    	// wait till the callback was executed
    	bps.wait();
    }