Skip to content

Instantly share code, notes, and snippets.

@malthe
Last active October 6, 2016 18:09
Show Gist options
  • Save malthe/a0232817937a54eea8f7c0b5d6dfdcd7 to your computer and use it in GitHub Desktop.
Save malthe/a0232817937a54eea8f7c0b5d6dfdcd7 to your computer and use it in GitHub Desktop.
use "promises"
use "ponytest"
class val IPEndpoint
"""Represents a host and service name.
The endpoint can be resolved to an IP address.
"""
let _host: String
let _service: String
let _promise: Promise[IPAddress] = _promise.create()
new create(host: String, service: String) =>
_host = host
_service = service
fun ref resolve(): Promise[IPAddress] =>
// To-Do: Actually spawn an asynchronous `getaddrinfo_a` call and
//somehow connect the result to the promise.
_promise(IPAddress)
_promise
class iso _IPEndpointTest is UnitTest
fun name(): String => "net/IPEndpoint"
fun ref apply(h: TestHelper) =>
let endpoint = IPEndpoint("localhost", "25")
let p = endpoint.resolve()
.next[String](
recover lambda(ip_address: IPAddress)(x: U32 = 42): String => ip_address.string() end end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment