future

English trip V2-B 17 Look to the Future Teacher: Russell

爱⌒轻易说出口 提交于 2019-11-28 04:58:11
In this lesson you will learn to talk about things in the future. 课上内容(Lesson) Positive 正面 future is good(美好) --> optimist(s) n. 乐观主义者;乐天派 optimist ic adj. 乐观的;乐观主义的 is bright 光明的 is wonderful 精彩;美好的 Negative 负面 future is bleak (黯淡) --> pessimist(s) n. 悲观主义者 pessimist ic adj. 悲观的,厌世的;悲观主义的 is bad 不好的 is worse 更不好的 词汇(Key Word ) assist vt. 帮助;促进 billionaire n.亿万富翁 cancer n.癌症;恶性肿瘤 climate n. 气候;风气;思潮;风土 control vt.控制 energy n.精力;能量 environmental adj. 环境的,周围的;有关环境的 eventually adv. 最后,终于 fuel n. 燃料;刺激因素;(为身体提供能量的)食物 hurricane /ˈhɜːrəkeɪn/ n.飓风 # 龙卷风 tornado # 暴风 storm invest vt.投资;投入 planet /'plæ

Scala waiting for sequence of futures

房东的猫 提交于 2019-11-28 04:23:23
I was hoping code like follows would wait for both futures, but it does not. object Fiddle { val f1 = Future { throw new Throwable("baaa") // emulating a future that bumped into an exception } val f2 = Future { Thread.sleep(3000L) // emulating a future that takes a bit longer to complete 2 } val lf = List(f1, f2) // in the general case, this would be a dynamically sized list val seq = Future.sequence(lf) seq.onComplete { _ => lf.foreach(f => println(f.isCompleted)) } } val a = FuturesSequence I assumed seq.onComplete would wait for them all to complete before completing itself, but not so; it

Future[Option] in Scala for-comprehensions

心已入冬 提交于 2019-11-28 04:07:49
I have two functions which return Futures. I'm trying to feed a modified result from first function into the other using a for-yield comprehension. This approach works: val schoolFuture = for { ud <- userStore.getUserDetails(user.userId) sid = ud.right.toOption.flatMap(_.schoolId) s <- schoolStore.getSchool(sid.get) if sid.isDefined } yield s However I'm not happy with having the "if" in there, it seems that I should be able to use a map instead. But when I try with a map: val schoolFuture: Future[Option[School]] = for { ud <- userStore.getUserDetails(user.userId) sid = ud.right.toOption

手工创建一个线程池

白昼怎懂夜的黑 提交于 2019-11-28 04:02:14
手工创建一个线程池,执行callable任务 /** * @Information: * @Author: HeHaoYuan * @Date: Created at 13:48 on 2019/8/12 * @Package_Name: PACKAGE_NAME */ import java.util.concurrent.*; public class MyExecutorService implements Callable { int tick = 20; @Override public String call() throws Exception { for (int i = 0; i < 20; i++) { if (tick > 0) { System.out.println(Thread.currentThread().getName()+"票还剩下" + tick-- + "张"); } } return "票已经卖完"; } } class ExecutorTest { public static void main(String[] args) throws ExecutionException, InterruptedException { MyExecutorService thread1 = new MyExecutorService(); /** *

Futures vs. Promises

只愿长相守 提交于 2019-11-28 02:38:34
I'm confusing myself with difference between a future and a promise. Obviously, they have different methods and stuff, but what is the actual use case? Is it?: when I'm managing some async task, I use future to get the value "in future" when I'm the async task, I use promise as the return type to allow the user get a future from my promise Future and Promise are the two separate sides of an asynchronous operation. std::promise is used by the "producer/writer" of the asynchronous operation. std::future is used by the "consumer/reader" of the asynchronous operation. The reason it is separated

What's the difference between a Future and a Promise?

纵饮孤独 提交于 2019-11-28 02:32:38
What's the difference between Future and Promise ? They both act like a placeholder for future results, but where is the main difference? According to this discussion , Promise has finally been called CompletableFuture for inclusion in Java 8, and its javadoc explains: A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion. An example is also given on the list: f.then((s -> aStringFunction(s)).thenAsync(s -> ...); Note that the final API is slightly different but

ToRowCountQuery seems to ignore groupings

↘锁芯ラ 提交于 2019-11-28 02:04:04
I'm trying to create a rowcount-query from a regular query, but the resulting SQL seems to lack the GROUP BY resulting in a wrong count. Does anyone know what I'm doing wrong. First the queries: var query = Session.QueryOver<InkoopFactuurListItem>() .Where(i => i.KlantId == Klant.Id) .AndRestrictionOn(i => i.Status).IsIn(statussen) .SelectList(list => list .SelectGroup(h => h.Id).WithAlias(() => dto.Id) .SelectGroup(h => h.Banknummer).WithAlias(() => dto.Banknummer) .SelectGroup(h => h.CrediteurNaam).WithAlias(() => dto.CrediteurNaam) .SelectGroup(h => h.DienstType).WithAlias(() => dto

Choosing optimal number of Threads for parallel processing of data

陌路散爱 提交于 2019-11-28 00:56:53
问题 Let's say I have a task with processing 1 million sentences. For each sentence, I need to do something with it, and it makes no matter what particular order they are processed in. In my Java program I have a set of futures partitioned from my main chunk of work with a callable that defines the unit of work to be done on a chunk of sentences, and I'm looking for a way to optimize the number of threads I allocate to work through the big block of sentences, and later recombine all the results of

Are Futures in Scala really functional?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 00:54:46
问题 I am reading this blog post that claims Futures are not "functional" since they are just wrappers of side-effectful computations. For instance, they contain RPC calls, HTTP requests, etc. Is it correct ? The blog post gives the following example: def twoUsersFeed(a: UserHandle, b: UserHandle) (implicit ec: ExecutionContext): Future[Html] = for { feedA <- usersFeed(a) feedB <- usersFeed(b) } yield feedA ++ feedB you lose the desired property: consistent results (the referential transparency).