When should I use a FutureBuilder?

FutureBuilder removes boilerplate code. Let’s say you want to fetch some data from the backend on page launch and show a loader until data comes. Tasks for ListBuilder: Have two state variables, dataFromBackend and isLoadingFlag On launch, set isLoadingFlag = true, and based on this, show loader. Once data arrives, set data with what you … Read more

What is the true meaning of pass-by-reference in modern languages like Dart?

Quick answer: what gets passed to your functions cookEggs and cookOne are references to the objects, not to the variables (which would be real pass-by-reference). The term pass-by-reference is often misused to mean pass-references-by-value: many languages only have pass-by-value semantics, where the values that are passed around are references (i.e. pointers, without the dangerous features). … Read more

Why does Future::select choose the future with a longer sleep period first?

TL;DR: use tokio::time If there’s one thing to take away from this: never perform blocking or long-running operations inside of asynchronous operations. If you want a timeout, use something from tokio::time, such as delay_for or timeout: use futures::future::{self, Either}; // 0.3.1 use std::time::Duration; use tokio::time; // 0.2.9 #[tokio::main] async fn main() { let time_out1 = … Read more

Waiting on a list of Future

You can use a CompletionService to receive the futures as soon as they are ready and if one of them throws an exception cancel the processing. Something like this: Executor executor = Executors.newFixedThreadPool(4); CompletionService<SomeResult> completionService = new ExecutorCompletionService<SomeResult>(executor); //4 tasks for(int i = 0; i < 4; i++) { completionService.submit(new Callable<SomeResult>() { public SomeResult call() … Read more

What are the differences between Deferred, Promise and Future in JavaScript?

These answers, including the selected answer, are good for introducing promises conceptually, but lacking in specifics of what exactly the differences are in the terminology that arises when using libraries implementing them (and there are important differences). Since it is still an evolving spec, the answer currently comes from attempting to survey both references (like … Read more

How do I synchronously return a value calculated in an asynchronous Future in stable Rust?

Standard library futures Let’s use this as our minimal, reproducible example: async fn example() -> i32 { 42 } Call executor::block_on: use futures::executor; // 0.3.1 fn main() { let v = executor::block_on(example()); println!(“{}”, v); } Tokio Use the tokio::main attribute on any function (not just main!) to convert it from an asynchronous function to a … Read more

How to Eager Load Associations without duplication in NHibernate?

Fetching Collections is a difficult operation. It has many side effects (as you realized, when there are fetched more collections). But even with fetching one collection, we are loading many duplicated rows. In general, for collections loading, I would suggest to use the batch processing. This will execute more SQL queries… but not so much, … Read more