future-util


License

License

MIT
GroupId

GroupId

com.github.tkawachi
ArtifactId

ArtifactId

future-util_2.11
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

future-util
future-util
Project URL

Project URL

https://github.com/tkawachi/future-util/
Project Organization

Project Organization

com.github.tkawachi
Source Code Management

Source Code Management

https://github.com/tkawachi/future-util/

Download future-util_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tkawachi/future-util_2.11/ -->
<dependency>
    <groupId>com.github.tkawachi</groupId>
    <artifactId>future-util_2.11</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.tkawachi/future-util_2.11/
implementation 'com.github.tkawachi:future-util_2.11:0.0.2'
// https://jarcasting.com/artifacts/com.github.tkawachi/future-util_2.11/
implementation ("com.github.tkawachi:future-util_2.11:0.0.2")
'com.github.tkawachi:future-util_2.11:jar:0.0.2'
<dependency org="com.github.tkawachi" name="future-util_2.11" rev="0.0.2">
  <artifact name="future-util_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.tkawachi', module='future-util_2.11', version='0.0.2')
)
libraryDependencies += "com.github.tkawachi" % "future-util_2.11" % "0.0.2"
[com.github.tkawachi/future-util_2.11 "0.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.4

test (2)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 2.2.0
org.scalacheck : scalacheck_2.11 jar 1.11.6

Project Modules

There are no modules declared in this project.

future-util

Utilities for scala.concurrent.Future.

Add a following line to build.sbt.

libraryDependencies += "com.github.tkawachi" %% "future-util" % "0.0.2"

FutureScheduler

FutureScheduler schedules an execution after certain time.

Using Thread.sleep() blocks the running thread. It's not recommended to waste a thread when working with Future.

// NG: Blocking the thread in ExecutionContext.
val futureSum: Future[Int] = Future {
	Thread.sleep(1000)
	1 + 1
}

With FutureScheduler you can write:

import scala.concurrent.duration._
import com.tkawachi.github.future.FutureScheduler

// OK: Non-blocking.
val futureSum: Futue[Int] = FutureScheduler.schedule(1.second) {
	1 + 1
}

You can use akka.pattern.after() if you're using Akka. Otherwise try FutureScheduler.

NOTE: FutureScheduler uses one daemon thread to schedule executions.

Versions

Version
0.0.2
0.0.1