Giter Club home page Giter Club logo

scala-futures-promises's People

Contributors

tdauth avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

cliffchou

scala-futures-promises's Issues

Remove orElseWithFirstNSucc

get is blocking.
Use transformWith/flatMap.
Other than that the whole implementation does not make any sense.

Refactor trait Prim to Base

In Haskell it is

-- Primitive set of (promise/future) features, specified in terms of a constructor class.
-- Inspired by Scala FP (= Scala's futures and promises).
class Base t where
  newB :: IO (t a)
  getB :: t a -> IO (Maybe a)
  tryCompleteB :: t a -> IO (Maybe a) -> IO Bool
  onCompleteB :: t a -> (Maybe a -> IO ()) -> IO ()

Rename our Prim trait to Base and all the methods.

Make Util.async a derived method

It can use the creation of a promise and a future together with Executor.submit.
However, the executor information should be kept in the future, so pass it as construction parameter.

Fix data race bug in firstN and firstNSucc

There is a data race bug in the firstN and firstNSucc implementations. Make sure that the vector element is added BEFORE the promise is completed. Therefore, do not check if c == n but if the vector's size == n!

Maybe we could use a threadsafe vector like in the C++ implementation and two atomic counters.
Remove the unnecessary done variable.
Look at: https://www.scala-lang.org/api/2.12.1/scala/collection/parallel/immutable/ParVector.html
And for performance at: https://docs.scala-lang.org/overviews/collections/performance-characteristics.html

Check if Future.find can be used to implement firstSucc and fix the implementation in NonDerivedFuture.firstSucc

This is the code from the current Scala FP implementation:

final def find[T](futures: scala.collection.immutable.Iterable[Future[T]])(p: T => Boolean)(implicit executor: ExecutionContext): Future[Option[T]] = {
    def searchNext(i: Iterator[Future[T]]): Future[Option[T]] =
      if (!i.hasNext) successful[Option[T]](None)
      else {
        i.next().transformWith {
          case Success(r) if p(r) => successful(Some(r))
          case other => searchNext(i)
        }
      }
    searchNext(futures.iterator)
  }

This looks like searchNext is called once in the beginning for the first future. It registers a callback which waits for the completion and then continues to register a callback for the next future, if the current one does not match the predicate. If this is the case, it does not prefer futures which complete first but futures which are first in the collection.
Therefore, it cannot be used to implement firstSucc.

Add benchmark suite

We want to compare the performance of our derived combinators with the performance of the existing combinators from Scala FP.

First, we need real world use cases which might be hard to find.

Maybe usage of the playframework? Akka based HTTP server?
If we use Akka, we cannot easily compare the performance.

If there is no real world examples, at least compare the performance by executing binary trees similiar to https://github.com/tdauth/cpp-futures-promises/blob/master/src/performance/performance_combinators.cpp

Add memory exhaustion tests for all implementations

Promise linking can fix this problem.

The old test AbstractRecursiveThenWithMemoryTest did not pass the correct index in thenWith.
Therefore, it run in an endless loop.
Fix it.

Java's CompletableFuture does not seem to have something like flatMap.
How can we reproduce this test with Java's implementation?

Fix failing unit tests

Some unit tests fail sometimes (not always), for example the successful test of firstNWithFirst.
Fix them all.

firstSucc should never lead to starvation of the program

We have mentioned in the C++ paper: "Method firstSucc imposes the condition that the first successful future shall be chosen. Instead of tryComplete we employ trySuccess. If both fail, we rely on the
following assumption. The promise will be deleted and then the resulting future fails.
This is a standard assumption found in C++17 and Folly."

This cannot be expected in Scala since it has a garbage collection. Therefore, make sure that firstSucc fails with the final exception if both futures fail to prevent starvation.

Adapt to Haskell-based implementation

We use the two traits Prim[T] and FP[T] which combined will result in a future and promise implementation.
We need unit tests to cover all functionality.
We need benchmarks:

  • binary tree for all combinators which take two or more futures
  • followedBy.followedBy.followedBy ....
  • onComplete multiple times
  • tryComplete multiple times on list of uncompleted promises

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.