-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from dvgica/managerial-twitter-util
Add conversions to/from Twitter Util
- Loading branch information
Showing
12 changed files
with
119 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
managerial-twitter-util/src/main/scala/ca/dvgi/managerial/twitter/util/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ca.dvgi.managerial.twitter | ||
|
||
import ca.dvgi.{managerial => m} | ||
import com.twitter.{util => tu} | ||
|
||
package object util { | ||
implicit class CompatibleManagerialManaged[T](val managed: m.Managed[T]) extends AnyVal { | ||
def asTwitterUtil: tu.Managed[T] = new tu.Managed[T] { | ||
def make() = new tu.Disposable[T] { | ||
val underlying = managed.build() | ||
def get = underlying.get | ||
def dispose(deadline: tu.Time) = tu.Future { underlying.teardown() } | ||
} | ||
} | ||
} | ||
|
||
implicit class CompatibleTwitterUtilManaged[T](val managed: tu.Managed[T]) extends AnyVal { | ||
def asManagerial: m.Managed[T] = new m.Managed[T] { | ||
def build() = new m.Resource[T] { | ||
val underlying = managed.make() | ||
def get = underlying.get | ||
def teardown() = tu.Await.result(underlying.dispose()) | ||
} | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...gerial-twitter-util/src/test/scala/ca/dvgi/managerial/twitter/util/AsManagerialTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ca.dvgi.managerial.twitter.util | ||
|
||
import ca.dvgi.{managerial => m} | ||
import com.twitter.{util => tu} | ||
|
||
class PackageTest extends munit.FunSuite { | ||
test("A Twitter Util Managed can be converted to a Managerial Managed") { | ||
val i = 42 | ||
var disposed = false | ||
val tum = new tu.Managed[Int] { | ||
def make() = new tu.Disposable[Int] { | ||
val underlying = i | ||
def get = underlying | ||
def dispose(deadline: tu.Time) = { | ||
disposed = true | ||
tu.Future.value(()) | ||
} | ||
} | ||
} | ||
|
||
val mm = tum.asManagerial | ||
assert(!disposed) | ||
|
||
val r = mm.build() | ||
assert(!disposed) | ||
|
||
assertEquals(r.get, i) | ||
assert(!disposed) | ||
|
||
r.teardown() | ||
assert(disposed) | ||
} | ||
|
||
test("A Managerial Managed can be converted to a Twitter Util Managed") { | ||
val i = 42 | ||
var torndown = false | ||
val managed = m.Managed(i)(_ => torndown = true) | ||
|
||
val tum = managed.asTwitterUtil | ||
assert(!torndown) | ||
|
||
val r = tum.make() | ||
assert(!torndown) | ||
|
||
assertEquals(r.get, i) | ||
assert(!torndown) | ||
|
||
r.dispose() | ||
assert(torndown) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.