future

Android: get result from callback (networking KOUSH ION)

佐手、 提交于 2019-12-05 21:13:40
问题 For my app I need to contact our API from our server which returns some JSON. While downloading the JSON, it should display a progressbar. I figured I should use Android's AsyncTask to handle the GUI while doing network operations, so I wrote the following within my Activity : class DownloadManager extends AsyncTask<String, Void, Boolean> { @Override protected void onPreExecute() { super.onPreExecute(); mLoadingSpinner.setVisibility(View.VISIBLE); } @Override protected Boolean doInBackground

Doctest not recognizing __future__.division

假装没事ソ 提交于 2019-12-05 20:58:11
问题 I have the following doctest written x.doctest : This is something: >>> x = 3 + 4 foo bar something else: >>> from __future__ import division >>> y = 15 >>> z = int('24') >>> m = z / y >>> print (m) 1.6 But when I ran python -m doctest x.doctest on python 2.7.11, the doctest didn't recognize from __future__ import division : ********************************************************************** File "x.doctest", line 11, in x.doctest Failed example: print (m) Expected: 1.6 Got: 1 ************

About Future.firstCompletedOf and Garbage Collect mechanism

眉间皱痕 提交于 2019-12-05 19:43:20
问题 I've encountered this problem in my real-life project and proved by my testing code and profiler. Instead of pasting "tl;dr" code, I'm showing you a picture and then describe it. Simply put, I'm using Future.firstCompletedOf to get a result from 2 Future s, both of which have no shared things and don't care about each other. Even though, which is the question I want to address, the Garbage Collector cannot recycle the first Result object until both of the Future s finished . So I'm really

spray Marshaller for futures not in implicit scope after upgrading to spray 1.2

家住魔仙堡 提交于 2019-12-05 19:17:50
问题 After updating to spray 1.2 I got a problem regarding my JSON-Marshallers that worked perfectly with 1.1. Doing the following inside a HttpService trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging => case class Test(hallo: String, test: String) implicit val storyJsonFormat = jsonFormat2(Test.apply) def test(implicit m : Marshaller[Future[Test]]) = 17 def hallo = test } leads to the following error: could not find implicit value for

Future cancel method documentation

£可爱£侵袭症+ 提交于 2019-12-05 18:47:33
According to http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html isDone returns true if cancel(boolean mayInterruptIfRunning) was called. After this method returns, subsequent calls to isDone() will always return true. However, it is possible that task is running and mayInterruptIfRunning is set to false . So, what should return isDone() right after that call? true because of cancel (which is wrong)? Also, it's not clear whether cancel(boolean) method returns false . P. S. I'm implementing some simple thread pool, so I'm inheriting from Future . After cancel(...) , isDone

Execute a for loop in parallel using CompletableFuture in Java and log the execution

僤鯓⒐⒋嵵緔 提交于 2019-12-05 18:34:15
I have a for loop which I am trying to parallelize using CompletableFuture. for (int i = 0; i < 10000; i++) { doSomething(); doSomethingElse(); } What I have till now is: for (int i = 0; i < 10000; i++) { CompletableFuture.runAsync(() -> doSomething()); CompletableFuture.runAsync(() -> doSomethingElse()); } I guess this serves the purpose but there is a requirement to print log just before the start and end of all the processing. If I do this: log("Started doing things"); for (int i = 0; i < 10000; i++) { CompletableFuture.runAsync(() -> doSomething()); CompletableFuture.runAsync(() ->

Future Recursion Patterns/Future Chaining of arbitrary length

孤街浪徒 提交于 2019-12-05 16:04:03
I'm curious about the best way to recursively build a chain of Akka futures which will run sequentially, if a doWork call in a future fails, the future should be retried up to 3 times, the chain should fail if it runs out of retry attempts. Assuming all doWork calls pass the returned future futChain should only complete. object Main extends App { val futChain = recurse(2) def recurse(param: Int, retries: Int = 3): Future[String] { Future { doWorkThatMayFailReturningString(param...) } recoverWith { case e => if (retries > 0) recurse(param, retries -1) else Future.failed(e) } flatMap { strRes =>

How to select between a future and stream in Rust?

你离开我真会死。 提交于 2019-12-05 11:59:56
I've just started experimenting with futures/tokio in Rust. I can do really basic things with just futures or just with streams. I was wondering how you can select between future and a stream. How can I extend the toy problem from the tokio documentation to use tokio_timer::Timer to do a timed HTTPS request? extern crate futures; extern crate native_tls; extern crate tokio_core; extern crate tokio_io; extern crate tokio_tls; use std::io; use std::net::ToSocketAddrs; use futures::Future; use native_tls::TlsConnector; use tokio_core::net::TcpStream; use tokio_core::reactor::Core; use tokio_tls:

Break the flow of CompletableFuture

旧巷老猫 提交于 2019-12-05 10:48:06
I have certain flow that runs async using the CompletableFuture , e.g.: foo(...) .thenAccept(aaa -> { if (aaa == null) { break! } else { ... } }) .thenApply(aaa -> { ... }) .thenApply(... So if my foo() returns null (in a future) I need to break very soon, otherwise, the flow continue. For now I have to check for null all the way, in every future block; but that is ugly. Would this be possible with CompletableFuture ? EDIT With CompletableFuture you can define your flow of async tasks, that are executed one after the other. For example, you may say: Do A, and when A finishes, do B, and then do

Why do cancelled Clojure futures continue using CPU?

倖福魔咒の 提交于 2019-12-05 10:25:31
问题 I have many examples of Java bytecode, all of which I'd like to execute from Clojure. Each sequence of bytecode may contain an infinite loop, in which case I'd like to stop running it after a couple of seconds. I've been looking at futures as a means of doing this. Having hunted around for a couple of implementations I've tried both this code: (deref (future (loop[a 1] (recur a)) :done!) 1000 :impatient!) ...and also the code at https://gist.github.com/3124000 In both cases, the loop appears