Skip to content

Instantly share code, notes, and snippets.

@jriecken
jriecken / AsyncController.diff
Last active December 31, 2016 23:17
Contextual Logging
import play.api.Logger
import org.slf4j.MDC
+import scala.concurrent.{ExecutionContext, Future}
import java.util.UUID
+import java.util.concurrent.Executors
-object SyncController extends Controller {
- def syncEndpoint(profileId: Long) = Action(parse.json) { req =>
+object AsyncController extends Controller {
+ implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(2))
+ // For this example, ensure the threads in the pool are already created
@jriecken
jriecken / a.js
Last active October 28, 2015 17:57
Steven Xu - Why I changed my functioning code to accommodate a test - code.hootsuite.com
var expectEditor = {
toBeClosed: function() {
expect($('.image-editor')).toBeHidden();
expect($('.drag-to-reposition')).toBeHidden();
expect($('.filter-options')).toBeHidden();
expect($('.tools')).toBeHidden();
expect($('.patterns')).toBeHidden();
expect($('.edit-img')).toBeVisible();
},
toBeOpen: function() {
@jriecken
jriecken / ec.scala
Created March 3, 2017 17:29
Prepare ExecutionContext without prepare method
// Something like this will likely allow propagation of thread-local information
val originalEc: ExecutionContext = ... // the actual execution context
// This will get called every time an implicit EC is necessary, effectively preparing the context
implicit def wrappedEc: ExecutionContext = {
val ctx = ...// capture thread local context here
new ExecutionContext {
override def execute(r: Runnable): Unit = originalEc.execute(new Runnable() {
override def run(): Unit {
val oldCtx = ... // get old context