Skip to content

Latest commit

 

History

History
126 lines (89 loc) · 3.77 KB

1.7.7.md

File metadata and controls

126 lines (89 loc) · 3.77 KB

1.7.7

This entire release is new features around AsyncCallback.


AsyncCallback instances

  • Added .fork and .fork_ which run the async computation in the background.

    The result of fork gives you access to (await: AsyncCallback[A], isComplete: CallbackTo[Boolean]) which you can use to join back up with it again later.

    fork_ on the other hand, returns nothing and is effectively fire-and-forget.

  • Added duration measuring methods that exist on Callback:

    def withDuration[B](f: (A, FiniteDuration) => AsyncCallback[B]): AsyncCallback[B]
    def logDuration    (fmt: FiniteDuration => String)             : AsyncCallback[A]
    def logDuration    (name: String)                              : AsyncCallback[A]
    def logDuration                                                : AsyncCallback[A]

AsyncCallback object

  • Added def awaitAll(as: AsyncCallback[_]*): AsyncCallback[Unit] to wait for a number of async processes to complete.

  • Added .countDownLatch(count: Int) which returns an AsyncCallback.CountDownLatch. It has the same purpose and semantics as Java's CountDownLatch.

    AsyncCallback.CountDownLatch {
      val countDown : Callback
      val await     : AsyncCallback[Unit]
      val isComplete: CallbackTo[Boolean]
      val pending   : CallbackTo[Int]
    }
  • Added .mutex which returns a AsyncCallback.Mutex:

    AsyncCallback.Mutex {
    
      /** Wrap a AsyncCallback so that it executes in the mutex.
        *
        * Note: THIS IS NOT RE-ENTRANT. Calling this from within the mutex will block.
        */
      def apply[A](ac: AsyncCallback[A]): AsyncCallback[A]
    }
  • Added .readWriteMutex which returns a AsyncCallback.ReadWriteMutex:

    AsyncCallback.ReadWriteMutex {
    
      /** Wrap a AsyncCallback so that it executes in the write-mutex.
        * There can only be one writer active at one time.
        *
        * Note: THIS IS NOT RE-ENTRANT. Calling this from within the read or write mutex will block.
        */
      def write[A](ac: AsyncCallback[A]): AsyncCallback[A]
    
      /** Wrap a AsyncCallback so that it executes in the read-mutex.
        * There can be many readers active at one time.
        *
        * Note: Calling this from within the write-mutex will block.
        */
      def read[A](ac: AsyncCallback[A]): AsyncCallback[A]
    }
  • Added ref[A](allowStaleReads = false, atomicWrites = true) which returns a AsyncCallback.Ref. A ref is effectively a "wrapper" for mutable variable. By default, setters and getters are atomic.

    AsyncCallback.Ref[A] {
      val get           : AsyncCallback[A]
      val getIfAvailable: CallbackTo[Option[A]]
    
      def set     (a: => A)            : AsyncCallback[Unit]
      def setSync (c: CallbackTo[A])   : AsyncCallback[Unit]
      def setAsync(c: AsyncCallback[A]): AsyncCallback[Unit]
    
      def setIfUnset     (a: => A)            : AsyncCallback[Boolean]
      def setIfUnsetSync (c: CallbackTo[A])   : AsyncCallback[Boolean]
      def setIfUnsetAsync(c: AsyncCallback[A]): AsyncCallback[Boolean]
    }
  • You can now add a _ suffix to the following to return an AsyncCallback[Unit] and be more efficient under-the-hood:

    • .traverse
    • .sequence
    • .traverseOption
    • .sequenceOption
  • The argument to .throwException is now by-name

  • Added def throwExceptionWhenDefined(o: => Option[Throwable]): AsyncCallback[Unit]


AsyncCallback.Barrier

  • Added isComplete: CallbackTo[Boolean] to synchronously query whether the barrier is complete or not.

  • Renamed waitForCompletion to await.

    waitForCompletion is still available but will result in a deprecation warning. Automatic migration is below.


Migration

find . -type f -name '*.scala' -exec perl -pi -e '
  s/\bwaitForCompletion\b/await/g;
' {} +