High performance C++ framework for concurrent servers
Public Member Functions | Related Functions | List of all members
seastar::gate Class Reference

Detailed Description

Facility to stop new requests, and to tell when existing requests are done.

When stopping a service that serves asynchronous requests, we are faced with two problems: preventing new requests from coming in, and knowing when existing requests have completed. The gate class provides a solution.

#include <gate.hh>

Public Member Functions

void enter ()
void leave ()
void check ()
future close ()
size_t get_count () const
 Returns a current number of registered in-progress requests.
bool is_closed () const
 Returns whether the gate is closed.

Related Functions

(Note that these are not member functions.)

template<typename Func >
auto with_gate (gate &g, Func &&func)

Member Function Documentation

◆ check()

void seastar::gate::check ( )

Potentially stop an in-progress request.

If the gate is already closed, a gate_closed_exception is thrown. By using enter() and leave(), the program can ensure that no further requests are serviced. However, long-running requests may continue to run. The check() method allows such a long operation to voluntarily stop itself after the gate is closed, by making calls to check() in appropriate places. check() with throw an exception and bail out of the long-running code if the gate is closed.

◆ close()

future seastar::gate::close ( )

Closes the gate.

Future calls to enter() will fail with an exception, and when all current requests call leave(), the returned future will be made ready.

◆ enter()

void seastar::gate::enter ( )

Registers an in-progress request.

If the gate is not closed, the request is registered. Otherwise, a gate_closed_exception is thrown.

◆ leave()

void seastar::gate::leave ( )

Unregisters an in-progress request.

If the gate is closed, and there are no more in-progress requests, the closed() promise will be fulfilled.

The documentation for this class was generated from the following file: