In [1]:
import scala.concurrent._
Out[1]:
In [2]:
implicit val ec = ExecutionContext.global
Out[2]:
In [3]:
Future(println("Hello"))
Future(3)
In [4]:
Thread.sleep(1000)
In [5]:
Future{Thread.sleep(3000); 3}
In [6]:
Future{Thread.sleep(10000); 30}
In [7]:
Future{Thread.sleep(3000); 3 ; println("completed")}
In [8]:
val n = 3
val fut = Future{Thread.sleep(3000); n}
In [9]:
val fut = Future{Thread.sleep(3000); 3}
val fut1 = fut.flatMap{k => Future{Thread.sleep(5000); k * k}}
In [10]:
val futVec = (1 to 10).toVector.map(n => Future{Thread.sleep(1000 * n); n})
val allDone = Future.sequence(futVec)
In [11]:
import sys.process._
println("git log -1".!!)
Out[11]:
In [12]:
import $ivy.`io.monix::monix:3.0.0`
Out[12]:
In [13]:
import monix.eval._
Out[13]:
In [14]:
Task(3)
Out[14]:
In [15]:
val task3 = Task.deferFuture(Future{Thread.sleep(6000); 3}(ec)).memoize
Out[15]:
In [16]:
import monix.execution.Scheduler.Implicits.global
val fut3 = task3.runToFuture
In [17]:
task3
Out[17]:
In [18]:
task3.runToFuture
In [19]:
val id = java.util.UUID.randomUUID().toString
kernel.publish.html("Starting", id)
for (i <- 1 to 10) {
Thread.sleep((200.0 + 200.0 * scala.util.Random.nextGaussian).toLong max 0L)
kernel.publish.updateHtml(s"Got item <b>#$i</b>", id)
}
kernel.publish.updateHtml("Got all items", id)
Out[19]:
In [20]:
for (i <- 1 to 10) {
kernel.publish.html(s"Got item <b>#$i</b>")
Thread.sleep((200.0 + 200.0 * scala.util.Random.nextGaussian).toLong max 0L)
}
In [21]:
import almond.display._
Html("<b>Bold stuff</b>")
Out[21]:
In [22]:
val handle = Html("<p> stuff comes here </p>")
In [23]:
handle.withContent("<b>Stuff becomes bold</b>").update()
In [24]:
val svgText = """<svg version="1.1"
baseProfile="full"
width="300" height="200"
xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="red" />
<circle cx="150" cy="100" r="80" fill="green" />
<text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text>
</svg>"""
Out[24]:
In [25]:
Html(svgText)
In [26]:
Future{Thread.sleep(5000); handle.withContent(svgText).update() }(ec)
In [32]:
handle.data
Out[32]:
In [33]:
handle.displayId
Out[33]:
In [35]:
handle.url
Out[35]:
In [36]:
handle.contentOrUrl
Out[36]:
In [37]:
handle.metadata
Out[37]:
In [27]:
interp
Out[27]:
In [28]:
interp.repositories
Out[28]:
In [29]:
Image
Out[29]:
In [30]:
Image.JPG
Out[30]:
In [ ]: