-
-
Save bpicolo/267098ff2f6612f54386c86ce396c8e9 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
class MemcachedNotify is TCPConnectionNotify | |
let _conn: _Connection tag | |
fun ref connect_failed(conn: TCPConnection ref) => None | |
fun ref connected(conn: TCPConnection ref) => | |
conn.set_nodelay(true) // Memcached + nodelay = better ? | |
_conn.connected() | |
fun ref received( | |
conn: TCPConnection ref, | |
data: Array[U8 val] iso, | |
times: USize val) | |
: Bool val | |
=> | |
_conn.respond(String.from_array(consume data)) | |
true | |
new iso create(c: _Connection tag) => | |
_conn = c | |
interface MemcachedConnection | |
be execute(command : Command val, cb: RespondCB val) | |
actor _Connection is MemcachedConnection | |
let _conn: TCPConnection val | |
let _pool: Pool tag | |
var _current: (RespondCB val | None) | |
new create(auth : AmbientAuth, host: String, port: String, pool: Pool) => | |
_conn = TCPConnection(auth, MemcachedNotify(this), host, port) | |
_pool = pool | |
_current = None | |
be execute(command : Command val, cb: RespondCB val) => | |
_current = cb | |
_conn.write(command.command()) | |
be respond(data : String) => | |
match _current | |
| None => None | |
| let cb : RespondCB val => cb(data) | |
end | |
be connected() => | |
Debug.out("Releasing connection into pool") | |
_pool.release(this) | |
fun _final() => | |
_conn.close() | |
actor Pool is ConnectionPool | |
var _auth : AmbientAuth | |
var _host: String | |
var _port: String | |
var _connections: List[MemcachedConnection tag] = List[MemcachedConnection tag] | |
var _pending: List[(Command val, Promise[Result])] = List[(Command val, Promise[Result])] | |
// conns are checked out, put back later | |
//// Problem is, I'm not allowed to close the conn in finalizer : ( | |
Error: | |
/Users/ben/projects/pony-memcache/pony-memcache/connection.pony:36:15: right side must be a subtype of left side | |
_conn = TCPConnection(auth, MemcachedNotify(this), host, port) | |
^ | |
Info: | |
/usr/local/Cellar/ponyc/0.20.0/packages/net/tcp_connection.pony:223:3: TCPConnection tag is not a subtype of TCPConnection val: tag is not a subcap of val | |
new create( | |
^ | |
Error: | |
/Users/ben/projects/pony-memcache/pony-memcache/connection.pony:55:20: receiver type is not a subtype of target type | |
_conn.close() | |
^ | |
Info: | |
/Users/ben/projects/pony-memcache/pony-memcache/connection.pony:55:9: receiver type: TCPConnection val | |
_conn.close() | |
^ | |
/usr/local/Cellar/ponyc/0.20.0/packages/net/tcp_connection.pony:853:3: target type: TCPConnection ref | |
fun ref close() => | |
^ | |
/Users/ben/projects/pony-memcache/pony-memcache/connection.pony:31:16: TCPConnection val is not a subtype of TCPConnection ref: val is not a subcap of ref | |
let _conn: TCPConnection val | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment