本文整理了Java中io.trane.future.Future.map()
方法的一些代码示例,展示了Future.map()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future.map()
方法的具体详情如下:
包路径:io.trane.future.Future
类名称:Future
方法名:map
[英]Maps the result of this future to another value.
[中]将此未来的结果映射到另一个值。
代码示例来源:origin: traneio/future
@Override
final Future<R> apply(final Future<T> result) {
return result.map(f);
}
}
代码示例来源:origin: traneio/future
@Override
public <U, R> Future<R> biMap(final Future<U> other, final BiFunction<? super T, ? super U, ? extends R> f) {
return other.map(u -> f.apply(value, u));
}
代码示例来源:origin: traneio/ndbc
private final Future<List<MysqlRow>> conv(final Future<List<Row>> f) {
return f.map(l -> l.stream().map(MysqlRow::create).collect(Collectors.toList()));
}
}
代码示例来源:origin: traneio/ndbc
private final Future<List<PostgresRow>> conv(final Future<List<Row>> f) {
return f.map(l -> l.stream().map(PostgresRow::create).collect(Collectors.toList()));
}
}
代码示例来源:origin: traneio/ndbc
public Future<List<T>> toList() {
ArrayList<T> unsynchronized = new ArrayList<>();
List<T> results = Collections.synchronizedList(unsynchronized);
return foreach(results::add).map(v -> unsynchronized);
}
代码示例来源:origin: traneio/ndbc
default public <R> Exchange<R> map(final Function<T, R> f) {
return channel -> run(channel).map(f::apply);
}
代码示例来源:origin: traneio/future
@Benchmark
public String mapConstN() throws CheckedFutureException {
Future<String> f = constFuture;
for (int i = 0; i < N.n; i++)
f = f.map(mapF);
return f.get(Duration.ofMillis(Long.MAX_VALUE));
}
代码示例来源:origin: traneio/future
@Benchmark
public String mapConst() throws CheckedFutureException {
return constFuture.map(mapF).get(Duration.ofMillis(Long.MAX_VALUE));
}
代码示例来源:origin: traneio/ndbc
@Override
public final Future<NettyChannel> get() {
final NettyChannel channel = new NettyChannel(charset);
return bootstrap(channel).map(v -> channel);
}
代码示例来源:origin: traneio/ndbc
@Override
public final Future<Boolean> isValid() {
return query(isValidQuery).map(r -> true).rescue(e -> Future.FALSE);
}
代码示例来源:origin: traneio/ndbc
@Override
public Future<Boolean> isValid() {
return query(isValidQuery).map(r -> true).rescue(e -> Future.FALSE);
}
代码示例来源:origin: traneio/ndbc
default public Exchange<T> onSuccess(final Function<T, Exchange<?>> f) {
return channel -> run(channel).flatMap(v -> f.apply(v).run(channel).map(ign -> v));
}
代码示例来源:origin: traneio/future
@Benchmark
public String setValueN() throws CheckedFutureException {
Promise<String> p = Promise.<String>apply();
Future<String> f = p;
for (int i = 0; i < N.n; i++)
f = f.map(mapF);
p.setValue(string);
return f.get(Duration.ofMillis(Long.MAX_VALUE));
}
代码示例来源:origin: traneio/future
@Benchmark
public String mapPromiseN() throws CheckedFutureException {
Promise<String> p = Promise.<String>apply();
Future<String> f = p;
for (int i = 0; i < N.n; i++)
f = f.map(mapF);
p.setValue(string);
return f.get(Duration.ofMillis(Long.MAX_VALUE));
}
代码示例来源:origin: traneio/ndbc
@Override
public Flow<Row> stream(PreparedStatement query) {
final Optional<Connection> transaction = currentTransaction.get();
if (transaction.isPresent())
throw new UnsupportedOperationException("Streaming doesn't support transactions.");
else
return Flow.from(pool.acquire().map(c -> c.stream(query).onComplete(() -> pool.release(c))));
}
代码示例来源:origin: traneio/future
/**
* Selects the index of the first satisfied future.
*
* @param list the list of futures to select from
* @return a future with the index of the first satisfied future of the list.
*/
public static <T> Future<Integer> selectIndex(final List<Future<T>> list) {
switch (list.size()) {
case 0:
return Future.exception(new IllegalArgumentException("Can't select from empty list."));
case 1:
return list.get(0).map(v -> 0);
default:
final Promise<Integer> p = Promise.apply(list);
int i = 0;
for (final Future<?> f : list) {
if (f instanceof SatisfiedFuture)
return Future.value(i);
final int ii = i;
f.ensure(() -> p.becomeIfEmpty(Future.value(ii)));
i++;
}
return p;
}
}
代码示例来源:origin: traneio/ndbc
@Test
public void transactionLocalFailure() throws CheckedFutureException {
final PreparedStatement ps = PreparedStatement.create("DELETE FROM " + table + " WHERE s = ?").setString("s");
try {
ds.transactional(() -> ds.execute(ps).map(v -> {
throw new IllegalStateException();
})).get(timeout);
assertTrue(false);
} catch (final IllegalStateException ex) {
}
final Iterator<Row> rows = ds.query("SELECT * FROM " + table).get(timeout).iterator();
assertTrue(rows.hasNext());
}
代码示例来源:origin: traneio/ndbc
public final Flow<Row> stream(final PreparedStatement query) {
Future<Fetch> fetch = run(extendedQueryStreamExchange.apply(query.query(), query.params()));
return Flow.batched(i -> {
Future<Flow<Row>> fut = fetch.flatMap(f -> run(f.fetch(i.intValue()))).map(Flow::from);
return Flow.from(fut);
});
}
代码示例来源:origin: traneio/ndbc
@Override
public Flow<Row> stream(PreparedStatement query) {
Future<Fetch> fetch = run(extendedQueryStreamExchange.apply(query.query(), query.params()));
return Flow.batched(i -> {
Future<Flow<Row>> fut = fetch.flatMap(f -> run(f.apply(i.intValue()))).map(Flow::from);
return Flow.from(fut);
});
}
代码示例来源:origin: traneio/ndbc
.apply(config.user(), config.password(), config.database(), "utf8").run(channel).map(connectionId -> {
return new io.trane.ndbc.mysql.Connection(channel, connectionId, marshallers, config.queryTimeout(),
config.scheduler(), simpleQueryExchange, simpleExecuteExchange, extendedQueryExchange,
内容来源于网络,如有侵权,请联系作者删除!