当前位置: 首页>>代码示例>>Java>>正文


Java Future类代码示例

本文整理汇总了Java中io.vavr.concurrent.Future的典型用法代码示例。如果您正苦于以下问题:Java Future类的具体用法?Java Future怎么用?Java Future使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Future类属于io.vavr.concurrent包,在下文中一共展示了Future类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendTweet

import io.vavr.concurrent.Future; //导入依赖的package包/类
private void sendTweet(final String text) {
    final Future<Status> updateResult = Future(
            () -> this.twitterHandler.getTwitter().updateStatus(text)
    );

    Stream(tweetTextArea, sendButton).forEach(ctr -> ctr.setDisable(true));

    updateResult.onComplete(res -> {
        res.onFailure(err ->
                Stages.stageOf(
                        "Couldn't send tweet !",
                        new ExceptionHandler(err).asPane()
                ).thenAccept(Stages::scheduleDisplaying));
        res.onSuccess(status ->
                stageManager.getSingle(Views.TWEET_VIEW).peek(Stages::scheduleHiding)
        );
    });
}
 
开发者ID:Tristan971,项目名称:Lyrebird,代码行数:19,代码来源:TweetController.java

示例2: tailRec

import io.vavr.concurrent.Future; //导入依赖的package包/类
public static <T, R> Future<R> tailRec(T initial, Function<? super T, ? extends Future<  ? extends io.vavr.control.Either<T, R>>> fn) {
    Future<? extends io.vavr.control.Either<T, R>> next[] = new Future[1];
    next[0] = Future.of(()->io.vavr.control.Either.left(initial));
    boolean cont = true;
    do {

        try{
            next[0].get();
        }catch(Throwable t){
            cont= false;
        }
        if(cont) {
            cont =  next[0].get().fold(s -> {
                next[0] = fn.apply(s);
                return true;
            }, pr -> false);
        }
    } while (cont);
    return next[0].map(e->e.get());
}
 
开发者ID:aol,项目名称:cyclops,代码行数:21,代码来源:Futures.java

示例3: narrow

import io.vavr.concurrent.Future; //导入依赖的package包/类
/**
 * Convert the HigherKindedType definition for a Future into
 *
 * @param completableFuture Type Constructor to convert back into narrowed type
 * @return Future from Higher Kinded Type
 */
public static <T> Future<T> narrow(final Higher<future, T> completableFuture) {
    if (completableFuture instanceof Future) {
        return (Future)completableFuture;

    }
    // this code should be unreachable due to HKT type checker
    final Box<T> type = (Box<T>) completableFuture;
    final Future<T> stage = type.narrow();
    return stage;

}
 
开发者ID:aol,项目名称:cyclops,代码行数:18,代码来源:FutureKind.java

示例4: ap

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Override
public <T, R> AnyM<future, R> ap(AnyM<future,? extends Function<? super T,? extends R>> fn, AnyM<future, T> apply) {
    Future<T> f = future(apply);
    Future<? extends Function<? super T, ? extends R>> fnF = future(fn);
    Future<R> res = FromCyclops.future(ToCyclops.future(fnF).combine(ToCyclops.future(f), (a, b) -> a.apply(b)));
    return Vavr.future(res);

}
 
开发者ID:aol,项目名称:cyclops,代码行数:9,代码来源:FutureAdapter.java

示例5: monadZeroFilter

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Test
public void monadZeroFilter(){

    FutureKind<String> opt = Futures.Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Futures.Instances.monadZero().filter((String t)->t.startsWith("he"), h))
                                 .convert(FutureKind::narrowK);

    assertThat(opt.get(),equalTo(Future.successful("hello").get()));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:11,代码来源:FuturesTest.java

示例6: foldLeft

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Test
public void  foldLeft(){
    int sum  = Futures.Instances.foldable()
                    .foldLeft(0, (a,b)->a+b, FutureKind.widen(Future.successful(4)));

    assertThat(sum,equalTo(4));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:8,代码来源:FuturesTest.java

示例7: futureTest

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Test
public void futureTest() {
    assertThat(Vavr.future(Future.of(() -> "hello world"))
                        .map(String::toUpperCase)
                        .to(ANY_M_LIST_FUNCTION),
               equalTo(Arrays.asList("HELLO WORLD")));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:8,代码来源:AnyJavaslangMTest.java

示例8: monadPlusNonEmpty

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Test
public void monadPlusNonEmpty(){

    Monoid<FutureKind<Integer>> m = Monoid.of(FutureKind.widen(cyclops.async.Future.future()), (a, b)->a.isCompleted() ? b : a);
    FutureKind<Integer> opt = Futures.Instances.<Integer>monadPlusK(m)
                                  .plus(FutureKind.widen(Future.successful(5)), FutureKind.widen(Future.successful(10)))
                                  .convert(FutureKind::narrowK);
    assertThat(opt.get(),equalTo(Future.successful(10).get()));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:10,代码来源:FuturesTest.java

示例9: futureFlatMapTest

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Test
public void futureFlatMapTest() {
    assertThat(Vavr.future(Future.of(() -> "hello world"))
                        .map(String::toUpperCase)
                        .to(ANY_M_LIST_FUNCTION),
               equalTo(Arrays.asList("HELLO WORLD")));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:8,代码来源:AnyJavaslangMTest.java

示例10: monad

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Test
public void monad(){

    FutureKind<Integer> opt = Futures.Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Futures.Instances.monad().flatMap((String v) -> Futures.Instances.unit().unit(v.length()), h))
                                 .convert(FutureKind::narrowK);

    assertThat(opt.get(),equalTo(Future.successful("hello".length()).get()));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:11,代码来源:FuturesTest.java

示例11: widenK

import io.vavr.concurrent.Future; //导入依赖的package包/类
public static <T> Higher<future,T> widenK(final Future<T> completableList) {

        return new FutureKind.Box<>(
                completableList);
    }
 
开发者ID:aol,项目名称:cyclops,代码行数:6,代码来源:FutureKind.java

示例12: fold

import io.vavr.concurrent.Future; //导入依赖的package包/类
default <R> FutureKind<R> fold(Function<? super Future<? super T>,? extends Future<R>> op){
    return widen(op.apply(this));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:4,代码来源:FutureKind.java

示例13: failed

import io.vavr.concurrent.Future; //导入依赖的package包/类
public static <T> FutureKind<T> failed(Throwable exception){
    return widen(Future.failed(exception));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:4,代码来源:FutureKind.java

示例14: save

import io.vavr.concurrent.Future; //导入依赖的package包/类
@Override
public AnyMValue<future, Boolean> save(String data){
    return anyM(Future.ofSupplier(ex,()->true));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:5,代码来源:AsyncTest.java

示例15: cyclopsFuture

import io.vavr.concurrent.Future; //导入依赖的package包/类
public static <T> Nested<Witness.future,future,T> cyclopsFuture(cyclops.async.Future<Future<T>> nested){
    cyclops.async.Future<Higher<future,T>> x = nested.map(FutureKind::widenK);

    return Nested.of(x,cyclops.async.Future.Instances.definitions(),Instances.definitions());
}
 
开发者ID:aol,项目名称:cyclops,代码行数:6,代码来源:Futures.java


注:本文中的io.vavr.concurrent.Future类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。