Questions tagged [future]

1

votes
1

answer
134

Views

How to properly wait until future is complete in dart

There is a slight bug in my app made with Flutter, that when the user has signed in, it fetches the user information from my database but not fast enough and causes a visual error on my front end of the app. The app has layouts that use the user information (name, location, and image) and it is not...
user3152311
-1

votes
0

answer
15

Views

Threads running sequentially when they should be concurrent

I have made a simple console application that reads text files, it is supposed to run concurrently not sequentially. Currently, in the console each thread runs until it finishes then the next thread starts, I want the threads to be running at the same time. I suspect the issue is that the promise is...
Aiden Faulconer
-1

votes
1

answer
26

Views

Need help to remove .get() usage with Java CompletableFuture

I am having trouble refactoring my code to remove .get() usages. Simplified problem goes like this: get a record, update it, then return some information. If the record does not exist, create a new record, then return some information. Pseudo version of working code: String getInfo(String id, Stri...
CrystalSquire
1

votes
2

answer
53

Views

Scala: Chaining futures, returning the first

I have a scenario where I have a Future[Something]: a which when successful needs to trigger a second Future[Unit]: b. I want to chain a and b together but I only care that a succeeds. if b fails I can just log an error and leave it at that: So far I have: def updateSomething(something: Something):...
Edd
1

votes
1

answer
63

Views

How to unit test CompletableFuture.thenAccept() by avoiding manual sleep

How to avoid manual sleep in unit test. Suppose In below code the Process and notify takes around 5 seconds for processing. So in order to complete the processing, i have added sleep of 5 seconds. public class ClassToTest { public ProcessService processService; public NotificationService notificat...
Niraj Sonawane
1

votes
2

answer
98

Views

While Loop with Futures in Scala

I have two methods: def getNextJob: Future[Option[Job]] def process(job: Job): Future[Unit] I would like to process all Jobs until there are no jobs remaining. I can do this with Await e.g. private def process()(implicit ctx: ExecutionContext): Future[Unit] = { var job: Option[Job] = Await.result(...
Edd
1

votes
2

answer
38

Views

Segmentation fault because of moved promise

I've passed a promise as a reference to a thread. Afterwards, the promise was moved into a vector via std::move. This is causing a segmentation fault when the software is executed. I reckon the reference in the thread is never updated after moving the promise? How can I pass the promise to the threa...
Gizmo
1

votes
1

answer
56

Views

Can't read a simple payload making HTTP request via hyper::client::Client: the trait bound `Body: Future` is not satisfied

I am attempting to convert a Result to a Buffer: let ufc_root: String = String::from('https://www.ufc.com/athletes/all?filters%5B0%5D=status%3A23'); // let ufc_root: String = String::from('https://www.google.com'); let https = HttpsConnector::new(4).unwrap(); let client = Client::builder().build::(h...
saxman
1

votes
1

answer
56

Views

In Scala, how do you use the value of the Future before it's used?

I'm trying to use values generated by a Scala Future: val x = for (i future.map(j => myArray(j) }
stats_man97531
1

votes
0

answer
55

Views

What if there was no future.isDone check in the invokeAll method

If we check the invokeAll method in AbstractExecutorService class, then we can see that following things are happening: Submission of the tasks in a for loop Running of another for loop. And in case the future is not completed , then do a get on it (to make sure that all the futures are finished bef...
Gaurav
1

votes
0

answer
41

Views

NodeJS: Delete futures running a thread to make new ones

I am working with legacy code written in Nodejs. There is a scheduler class which takes functions as input and starts a thread wrapped in a future. const t = threads.spawn(fn); future_ary.push(futures.newFuture(t)); Where the futures is just a wrapper class that does some book keeping and creates th...
danny
1

votes
0

answer
107

Views

HashMap with std::future as the key

Since we cannot get the arguments from std::future, I am trying to maintain a map between std::future and std::string. The following statement: std::unordered_map map fails with the following error: error: no match for call to '(const std::hash) (const std::future&)'...
UnderWood
1

votes
2

answer
642

Views

Calling pyspark function asynchronously with concurrent.futures

I am trying to call python functions which use pyspark rdd objects methods and are time-consuming which blocks my application. I need to write it in an async fashion so that my app doesn't get blocked. Here is a miniature version of the actual thing I want to do. from concurrent.futures import Futur...
DevanshBheda
1

votes
0

answer
923

Views

Proper way to create a Mono/Flux from a service that returns a future

How do I properly handle Monos built from futures? I'm trying to get my head around Spring Reactive (and Spring 5), watching all the videos and reading all the blogs I can find, but they all seem to stop short of doing something slightly more than just querying a database, or something else trivial...
Chris Turner
1

votes
0

answer
252

Views

How to collect both success and error within CompletableFutures?

I want to send multiple requests in parallel to a webservice. The results should be collected by success + error, and can then be further analyzed by the caller. public Map.Entry sendApiRequests(List reqs) { //will mostly remain null as errors won't occur frequently List errors = null; List futures...
membersound
1

votes
0

answer
255

Views

Completable Future Call 3 Methods in Parallel

I recently ran into an out of memory issue while using completable futures because there was too much garbage collection occuring and want to make sure I'm properly using CompletableFutures. I have 3 services which I want to call in parallel. Right now I have the following: final CompletableFuture...
Ryan M
1

votes
2

answer
550

Views

Set a timeout on individual threads when using CompletableFuture using a ThreadPoolExecutor

I have a program which executes things asynchronously using a ThreadPoolExecutor. I use CompletableFutures in Java 8 to schedule these tasks and then have them executed by the threads available in the thread pool. My code looks like this: public class ThreadTest { public void print(String m) { Syst...
chrisrhyno2003
1

votes
0

answer
170

Views

Resolving promises in rendering htmlwidgets

I was wondering if anyone could help with how the htmlwidgets and associated render functions work with promises (i.e promises and future packages) in shiny. I have been reading up and learning on how to integrate these things based on Joe Chengs articles and rstudioconf talk. E.g https://medium.com...
jamieRowen
1

votes
0

answer
138

Views

Building a Future API on top of Netty

I want to build an API based on Futures (from java.util.concurrent) that is powered by a custom protocol on top of Netty (version 4). Basic idea is to write a simple library that would abstract the underlying Netty implementation and make it easier to make requests. Using this library, one should be...
Nikola Ninkovic
1

votes
1

answer
132

Views

Cancel a Future after stopping an actor

I have an application with Master-Worker architecture. The Worker needs to do a heavy and long time job. And the Master needs to kill the job when we need. I've tried not to use Future and the worker cannot receive any message while working. So I tried to use Future instead. However, when the Worker...
Shyu Kevin
1

votes
1

answer
340

Views

What happens when the response from the CompletableFuture is ignored?

I am experimenting with CompletableFuture in making async API calls. I am trying to understand the implication of ignoring the response from a Future. The JVM technically executes the async API call and returns the result. But in case we have no CompletableFuture.get() call to retrieve the response...
chrisrhyno2003
1

votes
0

answer
178

Views

calling completableFuture in while loop for byteArrayOutputStream not working properly

CompletableFuture works fine with simple asynchronous task but i have tried same in while loop when reading a file and writing to multiple files as per below code:- BufferedInputStream bin = null; ReadableByteChannel channel = null; int bufferSize = 1048576; int readBufferSize = 1024*4; java.nio.Byt...
Harisingh Rajput
1

votes
1

answer
68

Views

How to debug CompletableStage deadlocks?

The most difficult debugging problem I've run across recently is deadlocks between asynchronous operations. For example, given two CompletionStage chains, where the first chain invokes a method that depends upon the completion of the second chain, and the second chain invokes a method that depends u...
Gili
1

votes
0

answer
21

Views

How to delay next async api call when an api doesn't respond?

I have a list of APIs that I have to asynchronously connect to and retrieve data. In that case, I'm creating a list of callable tasks. A callable class looks like: public class ConnectToApiCallable implements Callable { *variables & constructor* @Override public ReturnedStringAndDate call() throws...
Maciaz
1

votes
1

answer
180

Views

Why does returning CompletableFuture.completedFuture(…) from inside a try-catch block (appear to) cause this error? [duplicate]

This question already has an answer here: Generic type inference not working with method chaining? 1 answer I have a method that returns a CompletionStage at various points, but it appears that doing so from within a try-catch block causes an 'Incompatible types' error: Incompatible types Required:...
Andrew Cheong
1

votes
1

answer
125

Views

How can I implement a Future which is woken up from another thread in Futures 0.2?

I'm trying to find a simple way to implement the Future trait from the future crate, version 0.2.1: extern crate futures; use futures::executor::ThreadPool; use futures::prelude::*; use futures::task::Context; use std::{thread, time::Duration}; struct SendThree { firstTime: bool, } impl Future for S...
user2568161
1

votes
2

answer
160

Views

Filter out duplicates for CompletableFuture

I wanna to filter out the duplicates after the first CompletableFuture and then invoke the second stage using another CompletableFuture. What I tried: @FunctionalInterface public interface FunctionWithExceptions { R process(T t) throws E; } public static Predicate distinctByKey(FunctionWithExceptio...
Hearen
1

votes
0

answer
60

Views

Spark streaming - What happens to a Future after an RDD was totally finished?

The question is the following: What happens to a Future after a batch finishes in Spark ? I have an application that reads from a Kafka topic and writes to another one. Here is the main code: KafkaUtils .createDirectStream[String, SomeClass](options...) .foreachPartition( partition => { doSomeWork(p...
Ismail H
1

votes
1

answer
137

Views

Catching dangling or unused Futures in Scala

A common problem in our Scala code is that a call that returns a Future[T] will not be awaited (we commonly use the scala-async library because many of us are familiar with async/await from C#) or used at all; it is simply discarded. Is there any way to get a warning or is there a 3rd-party code ana...
Charles Crain
1

votes
1

answer
64

Views

vavr's Future don't execute some code, with method andThen

In this code, I have two methods using vavr library. From this library I am using Future with the method andThen, this method run when the future has been completed, and this is synchronous, but when the thread call to the method 'printTime' in this method, all program stop, and the test is success....
1

votes
0

answer
64

Views

ThreadPoolTaskExecutor deadlock

Our app is using the Spring @Async to start asynchronous tasks (e.g. to do parallel calls to REST APIs). Our ThreadPoolTaskExecutor has been configured with 16 corepoolsize, 128 maxpool and 128 queue size. Asynchronous tasks can start more async tasks and so on, these can become quite deeply nested....
Raipe
1

votes
0

answer
157

Views

How to avoid invoking CompletableFuture.thenCompose(x -> x)?

I get the feeling that I am misusing the CompletableFuture API. When invoking CompletableFuture.exceptionally() I routinely find myself needing to invoke another asynchronous process, which means that exceptionally() returns CompletableFuture instead of CompletableFuture. I then cast the result back...
Gili
1

votes
1

answer
310

Views

How to throw an exception on an CompletableFuture.get() call?

Is there a way to have mockito throw an exception on the CompletableFuture.get() call and not just the asynchronous method? For example, given the following (incorrect) test case: @Test public void whenRunnerThrows_thenReturn5xx() throws Exception { when(service.runAsync(any(),any())).thenThrow(new...
jeffaudio
1

votes
0

answer
43

Views

Java - Futures not Cancelling

I have had a problem with my futures returned from my ExecutorService not cancelling properly for some time. I have written an MCVE which I believe captures the root of my problems. Here is the code: public class MainTest extends Application { private ExecutorService threadPool = Executors.newFixedT...
Ivar Eriksson
1

votes
1

answer
330

Views

correct way to handle timeout in CompletableFuture.allof and logging the timed out futures

I've ItemDetails and ItemPriceDetails defined as below - class ItemDetails { private int itemId; private int uom; private int zipcode; private String promoCode; } class ItemPriceDetails { private int itemId; private int uom; private int zipcode; private float totalCost; private float totalTax; priva...
1

votes
1

answer
112

Views

In Scala Monix Scheduler how to propagate exceptions to main program?

I have a Monix Scheduler that scheduling error-prone task: import scala.concurrent.duration._ import monix.eval.Task import monix.execution.Scheduler import java.time._ scheduler.scheduleWithFixedDelay(0.seconds, 1.seconds) { IO(println('qq')) .map{ _ => if (Instant.now.getEpochSecond % 5 == 0) t...
WeiChing Lin
1

votes
0

answer
254

Views

Creating a chain of Vertx handler executions

From the start, sorry for bad English, I am working on it. My goal is to create http methods in vert.x. Each method consists of steps, which can be blocked by other steps. For simplifying one step can be blocked by exactly one another. I decided to create an AsyncMethodHandler which inside of handl...
hrimkm
1

votes
0

answer
172

Views

CompletableFuture - async task execution is erroneous?

My problem statement is that I have multiple monitor objects in place, and I have to execute all of them asynchronously and report their status to some external service success means if the task executed in 100 milliseconds, failure or timeout should be reported for tasks that takes more than 100...
Mozhi
1

votes
0

answer
13

Views

ScalaDoc with Futures

So is there any correct way to annotate futures in scaladoc (specifically failures)? @throws doesn't seem appropriate since the exceptions get wrapped in a Try (Failure). Was looking for something like a @failure tag. /** * @failure FooException If i is even * @failure BarException If i is odd */ de...
Vangogh500
1

votes
1

answer
156

Views

Completable future & Executor service and Java EE or application server - etier

I am creating flood of async tasks and executing them with the help of completablefuture supply async by passing custom executor service with the thread pool that i created. In tomcat i don't have to do anything specifically to manage the executor or task completion stage. The question is do i nee...
Mozhi

View additional questions