Created
October 27, 2017 18:17
-
-
Save bpicolo/ec2abf53aa29aec20c6e9d23b4fd1196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use "promises" | |
interface ConnectionPool | |
be execute(command: String, p: Promise[(String | None)]) | |
actor Pool | |
var _connections: Array[MemcachedConnection tag] = Array[MemcachedConnection tag] | |
var _host: String | |
var _port: String | |
new create(env: Env, host: String, port: String) => | |
_env = env | |
_host = host | |
_port = port | |
be execute(command : String, p: Promise[(String | None)]) => | |
// If a connection is available, what to do here is obvious | |
// The question is what to do when we have to asynchronously create | |
// a new connection, or otherwise wait for a connection to be available | |
// (at max pool size) | |
let conn = Connection(_env, _host, _port, this) | |
be release(MemcachedConnection tag) => | |
_connections.push(MemcachedConnection) | |
use "net" | |
class MemcachedNotify is TCPConnectionNotify | |
let _conn: Connection tag | |
fun ref connect_failed(conn: TCPConnection ref) => None | |
fun ref connected(conn: TCPConnection ref) => _conn.connected() | |
new iso create(c: Connection tag) => | |
_conn = c | |
interface MemcachedConnection | |
be execute(query: String) | |
actor Connection is MemcachedConnection | |
let _conn: TCPConnection tag | |
let _pool: Pool tag | |
new create(auth: AmbientAuth, host: String, port: String, pool: Pool) => | |
_conn = TCPConnection(auth, MemcachedNotify(this), host, port) | |
_pool = pool | |
be execute(query: String) => | |
None | |
be connected() | |
_pool.release(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment