Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions source/mysql/pool.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ debug(MYSQLN_TESTS)
import mysql.test.common;
}

version(Have_vibe_core) version = IncludeMySQLPool;
version(MySQLDocs) version = IncludeMySQLPool;
version(Have_vibe_core)
{
version = IncludeMySQLPool;
static if(is(typeof(ConnectionPool!Connection.init.removeUnused((c){}))))
version = HaveCleanupFunction;
}
version(MySQLDocs)
{
version = IncludeMySQLPool;
version = HaveCleanupFunction;
}

version(IncludeMySQLPool)
{
Expand Down Expand Up @@ -50,6 +59,10 @@ version(IncludeMySQLPool)

/// See: $(LINK http://vibed.org/api/vibe.core.connectionpool/ConnectionPool.maxConcurrency)
uint maxConcurrency;

/// See: $(LINK https://github.com/vibe-d/vibe-core/blob/24a83434e4c788ebb9859dfaecbe60ad0f6e9983/source/vibe/core/connectionpool.d#L113)
void removeUnused(scope void delegate(Connection conn) @safe nothrow disconnect_callback)
{}
}

/++
Expand Down Expand Up @@ -94,6 +107,7 @@ version(IncludeMySQLPool)
{
bool queuedForRelease = false;
}

}

/// Sets up a connection pool with the provided connection settings.
Expand Down Expand Up @@ -427,6 +441,30 @@ version(IncludeMySQLPool)
{
preparedRegistrations.clear();
}

version(HaveCleanupFunction)
{
/++
Removes all unused connections from the pool. This can
be used to clean up before exiting the program to
ensure the event core driver can be properly shut down.

Choose a reason for hiding this comment

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

If this function only exists under certain conditions, that should probably be explained in its doc comments here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated


Note: this is only available if vibe-core 1.7.0 or later is being
used.
+/
void removeUnusedConnections() @safe
{
// Note: we squelch all exceptions here, because vibe-core
// requires the function be nothrow, and because an exception
// thrown while closing is probably not important enough to
// interrupt cleanup.
m_pool.removeUnused((conn) @trusted nothrow {
try {
conn.close();
} catch(Exception) {}
});
}
}
}

@("registration")
Expand Down