-
-
Save rightfold/556a73d45bebd04e3370 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 Geocoder { | |
val queue = new LinkedBlockingQueue[(String, Promise[Point])]() | |
val httpClient = HttpClients.createDefault() | |
var stop = false | |
new Thread(new Runnable { | |
override def run() = | |
while (!stop) { | |
val (query, promise) = queue.poll() | |
val response = httpClient.execute(new HttpGet(s"http://maps.bing.com/blablabla?q=$query&blabla=bla")) | |
try { | |
println(response) | |
promise.success(Point(0.0, 0.0)) | |
} finally { | |
response.close() | |
} | |
} | |
}) | |
def schedule(query: String) = { | |
val promise = Promise[Point]() | |
queue.put((query, promise)) | |
promise.future | |
} | |
def close() = { | |
stop = true | |
httpClient.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment