Skip to content

Instantly share code, notes, and snippets.

View mgodave's full-sized avatar
🤟
move along, nothing to see here...

Dave Rusek mgodave

🤟
move along, nothing to see here...
  • Denver, CO
  • 01:28 (UTC -06:00)
View GitHub Profile
@mgodave
mgodave / actor.kt
Last active October 15, 2018 09:29
Kotlin actor
package actors
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.SettableFuture
import com.google.common.util.concurrent.MoreExecutors
import java.util.concurrent.Executors
import java.util.ArrayList
import java.util.concurrent.LinkedBlockingQueue
import com.google.common.util.concurrent.ListeningExecutorService
import java.util.concurrent.ThreadFactory
@mgodave
mgodave / futures.kt
Created November 14, 2013 04:35
Akka Futures API in Kotlin (for fun)
import com.google.common.util.concurrent.ListeningExecutorService
import com.google.common.util.concurrent.MoreExecutors
import java.util.concurrent.Executors
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.FutureCallback
import com.google.common.util.concurrent.SettableFuture
import java.util.ArrayList
object KFutures {
@mgodave
mgodave / CounterMutationBuilder.java
Created October 16, 2013 20:08
CRDT user API PoC
/*
* Copyright 2013 Basho Technologies Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright 2013 Basho Technologies Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
public class ChainingExample {
private final Executor mainPool;
private final Executor ioPool;
public ChainingExample(Executor mainPool, Executor ioPool) {
this.mainPool = mainPool;
this.ioPool = ioPool;
}
public class FunctionComposerExample {
private final Executor mainPool;
private final Executor ioPool;
public FunctionComposerExample(Executor mainPool, Executor ioPool) {
this.mainPool = mainPool;
this.ioPool = ioPool;
}
ListenableFuture<RowKey> rowKeyFuture = indexService.lookUp(query);
AsyncFunction<RowKey, QueryResult> queryFunction =
new AsyncFunction<RowKey, QueryResult>() {
public ListenableFuture<QueryResult> apply(RowKey rowKey) {
return dataService.read(rowKey);
}
};
ListenableFuture<QueryResult> queryFuture = transform(rowKeyFuture, queryFunction);
@mgodave
mgodave / FunctionCompositionBuilder.java
Last active December 16, 2015 21:29
Function Composition with Guava
package org.robotninjas.util;
import com.google.common.base.Function;
import com.google.common.util.concurrent.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@mgodave
mgodave / AsyncCommand.java
Created April 29, 2013 21:41
AsyncCommand
package org.robotninjas.util;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
public class AsyncCommand<V> {
package org.robotninjas.util;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.TimeLimiter;
import java.util.concurrent.Callable;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.TimeUnit;
public class TimeLimitedFutureTask<V> extends AbstractFuture<V> implements RunnableFuture<V> {