Creating an empty Scala Future to be completed externally

Is it possible / how to create an empty Future, set the necessary callbacks for its completion, and then set its result at a different point in time? In pseudocode (uncompilable) that would look like the following: val future: Future[Int] = Future.empty() future.onComplete { case Failure(exception) => println(s"Exception: $exception") case Success(value) => println(s"Done: $value") }… Read More Creating an empty Scala Future to be completed externally

Are functions in Swift called in parallel by default or does the first one need to finish execution before the next is called?

I’d like to understand whether a function that may take time to execute will delay the execution of the function after it. Let me share the code: First, we have a function that calculates an average value based on. This should be almost instant if the user has a few habits, but if the user… Read More Are functions in Swift called in parallel by default or does the first one need to finish execution before the next is called?

Go concurrency, goroutine synchronization and closing channels

Familiarizing myself with concurrency, so started writing a simple ping cli with concurrent calls (let’s ignore that I’m not really measuring pings). Problem is, I can’t close the channel properly for the range loop while also waiting for all the goroutines to finish. If I want to concurrently call the ping function, I can’t synchronize… Read More Go concurrency, goroutine synchronization and closing channels

Waiting on main thread for callback methods

I am very new to Scala and following the Scala Book Concurrency section (from docs.scala-lang.org). Based off of the example they give in the book, I wrote a very simple code block to test using Futures: import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global import scala.util.{Failure, Success} object Main { def main(args: Array[String]): Unit = { val a =… Read More Waiting on main thread for callback methods

How to get size_t value out of std::thread::id on Windows?

How to get size_t value out of std::thread::id on Windows? The thread-id is 9120 (id and this_id). I tried a few ANSI C++ ways, but they resulted in a different id: Code: int main() { // Win API: const auto id = Concurrency::details::platform::GetCurrentThreadId(); // OK // ANSI C++: const std::thread::id this_id = std::this_thread::get_id(); // OK… Read More How to get size_t value out of std::thread::id on Windows?

Are indexes built CONCURRENTLY different in any way?

Does PostgreSQL CREATE INDEX CONCURRENTLY mean that even after initial index build, new and future inserts won’t be indexed immediately (strongly consistent in terms of indexing)? >Solution : No. CREATE INDEX with the modifier CONCURRENTLY produces exactly the same kind of index as without the modifier. CONCURRENTLY only changes the way the index is created… Read More Are indexes built CONCURRENTLY different in any way?

Java unexpected concurrent result

While testing concurrency, I found something unexpected. Concurrency was controlled using concurrentHashMap and AtomicLong. public class HumanRepository { private final static Map<Long, Human> STORE = new ConcurrentHashMap<>(); private AtomicLong sequence = new AtomicLong(); public void save(Human human) { STORE.put(sequence.incrementAndGet(), human); } public int size() { return STORE.size(); } public Long getSeq() { return sequence.get(); }… Read More Java unexpected concurrent result