Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ExecutionContext to .call signature #57

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
language: scala

sudo: required

dist: trusty

jdk:
- oraclejdk8
scala:
- 2.11.2
- 2.11.11
- 2.12.2

# Taken from https://github.com/typelevel/cats/blob/master/.travis.yml
cache:
directories:
- $HOME/.sbt/0.13/dependency
- $HOME/.sbt/boot/scala*
- $HOME/.sbt/launchers
- $HOME/.ivy2/cache
- $HOME/.nvm

before_cache:
- du -h -d 1 $HOME/.ivy2/cache
- du -h -d 2 $HOME/.sbt/
- find $HOME/.sbt -name "*.lock" -type f -delete
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete
18 changes: 7 additions & 11 deletions autowire/jvm/src/test/scala-2.11/autowire/InteropTests.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package autowire
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}

import org.objenesis.strategy.StdInstantiatorStrategy
import utest._
import scala.concurrent.Future
import java.io.{ObjectInputStream, ByteArrayInputStream, ObjectOutputStream, ByteArrayOutputStream}
import utest.framework.Tree
import utest.framework.Test
import utest.framework.ExecutionContext.RunNow

import scala.reflect.ClassTag
import utest._
import scala.pickling._
import json._
import org.objenesis.strategy.StdInstantiatorStrategy


object InteropTests extends TestSuite{
Expand All @@ -34,7 +30,7 @@ object InteropTests extends TestSuite{
}
def routes = Server.route[Api](Controller)
}
import Bundle.{Client, Server}
import Bundle.Client

val res1 = await(Client[Api].add(1, 2, 3).call())
val res2 = await(Client[Api].add(1).call())
Expand Down Expand Up @@ -70,7 +66,7 @@ object InteropTests extends TestSuite{
}
def routes = Server.route[Api](Controller)
}
import Bundle.{Client, Server}
import Bundle.Client

val res1 = await(Client[Api].add(1, 2, 3).call())
val res2 = await(Client[Api].add(1).call())
Expand Down Expand Up @@ -104,7 +100,7 @@ object InteropTests extends TestSuite{
}
def routes = Server.route[Api](Controller)
}
import Bundle.{Client, Server}
import Bundle.Client

val res1 = await(Client[Api].add(1, 2, 3).call())
val res2 = await(Client[Api].add(1).call())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package autowire

object ScalaVersionStubs {
type compileTimeOnly = scala.annotation.compileTimeOnly
}
8 changes: 4 additions & 4 deletions autowire/shared/src/main/scala/autowire/Internal.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package autowire


import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}
import language.experimental.macros


Expand All @@ -16,16 +16,16 @@ object Internal{
* call-Future extension method a chance to run first
*/
trait LowPri {
implicit def clientCallable[T](t: T) = new Internal.ClientCallable[T]
implicit def clientCallable[T](t: T): ClientCallable[T] = new Internal.ClientCallable[T]
}

/**
* A synthetic type purely meant to hold the `.call()` macro; gets
* erased completely when the macro-implementation of `.call()` runs
*/
class ClientCallable[T]{
class ClientCallable[T] {
@ScalaVersionStubs.compileTimeOnly(".call() method is synthetic and should not be used directly")
def call(): Future[T] = macro Macros.clientMacro[T]
def call()(implicit ec: ExecutionContext): Future[T] = macro Macros.clientMacro[T]
}

type FailMaybe = Either[Error.Param, Any]
Expand Down
10 changes: 4 additions & 6 deletions autowire/shared/src/main/scala/autowire/Macros.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package autowire

import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}
import scala.reflect.macros.Context
import language.experimental.macros
import acyclic.file

import Core._

object Macros {
Expand Down Expand Up @@ -145,9 +144,8 @@ object Macros {
}


def clientMacro[Result]
(c: Context)
()
def clientMacro[Result](c: Context)
()(ec: c.Expr[ExecutionContext])
(implicit r: c.WeakTypeTag[Result])
: c.Expr[Future[Result]] = {

Expand Down Expand Up @@ -252,7 +250,7 @@ object Macros {
case (q"$thing.$name", _) if name.toString.contains("$default$") => false
case _ => true
}
.map { case (t, param: Symbol) => q"${param.name.toString} -> $proxy.self.write($t)"}
.map { case (t, param: Symbol) => q"${param.name.toString} -> $proxy.self.write[${param.typeSignature}]($t)"}

} yield {
val fullPath = prePath ++ memPath
Expand Down
9 changes: 2 additions & 7 deletions autowire/shared/src/test/scala/autowire/UpickleTests.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package autowire
import utest._
import utest.framework._
import utest.framework.ExecutionContext.RunNow
import upickle.Js
import upickle.default._
import acyclic.file
import utest._
import utest.framework.ExecutionContext.RunNow


object UpickleTests extends TestSuite{
Expand All @@ -14,12 +12,10 @@ object UpickleTests extends TestSuite{
def routes = Server.route[Api](Controller)
}
import Bundle.{Client, Server}

import utest.PlatformShims.await

val tests = TestSuite{
'example{
import upickle._

// shared API interface
trait MyApi{
Expand Down Expand Up @@ -51,7 +47,6 @@ object UpickleTests extends TestSuite{
MyClient[MyApi].doThing(3, "lol").call().foreach(println)
}
'inheritedTraits{
import upickle._

// It should also be possible to separate the API into several controllers that
// only implement the logic of their corresponding protocols. The controllers are
Expand Down
20 changes: 20 additions & 0 deletions autowire/test.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
val str1 =
"""
|[info]
|[info] * - compileError("123.call()").check(
|[info] ^
""".stripMargin

val str2 =
"""
|[info]
|[info] * - compileError("123.call()").check(
|[info] ^
""".stripMargin

str1 == str2

val stripped = str1.reverse.dropWhile("\n ".toSet.contains).reverse
val normalizedPos = "\n" + str2

str1 == str2
75 changes: 35 additions & 40 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,69 +1,64 @@
crossScalaVersions := Seq("2.10.4", "2.11.8", "2.12.0")
crossScalaVersions in ThisBuild := Seq("2.10.6", "2.11.11", "2.12.2")

val autowire = crossProject.settings(
organization := "com.lihaoyi",

version := "0.2.6",
organization := "de.daxten",
version := "0.3.1",
name := "autowire",
scalaVersion := "2.11.8",
scalaVersion := "2.11.11",
autoCompilerPlugins := true,
addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.5"),
libraryDependencies ++= Seq(
"com.lihaoyi" %% "acyclic" % "0.1.5" % "provided",
"com.lihaoyi" %%% "utest" % "0.4.4" % "test",
"com.lihaoyi" %%% "utest" % "0.4.7" % "test",
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"com.lihaoyi" %%% "upickle" % "0.4.4" % "test"
) ++ (
) ++ {
if (!scalaVersion.value.startsWith("2.10.")) Nil
else Seq(
compilerPlugin("org.scalamacros" % s"paradise" % "2.0.0" cross CrossVersion.full),
"org.scalamacros" %% s"quasiquotes" % "2.0.0"
compilerPlugin("org.scalamacros" % s"paradise" % "2.0.1" cross CrossVersion.full),
"org.scalamacros" %% s"quasiquotes" % "2.0.1"
)
),
},
testFrameworks += new TestFramework("utest.runner.Framework"),
// Sonatype
// Bintray
isSnapshot := false,
publishArtifact in Test := false,
publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"),

pomExtra :=
<url>https://github.com/lihaoyi/ajax</url>
<licenses>
<license>
<name>MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<scm>
<url>git://github.com/lihaoyi/ajax.git</url>
<connection>scm:git://github.com/lihaoyi/ajax.git</connection>
</scm>
<developers>
<developer>
<id>lihaoyi</id>
<name>Li Haoyi</name>
<url>https://github.com/lihaoyi</url>
</developer>
</developers>
bintrayReleaseOnPublish in ThisBuild := true,
licenses in ThisBuild += ("MIT", url("http://opensource.org/licenses/MIT")),
bintrayVcsUrl in ThisBuild := Some("[email protected]:daxten/autowire"),
homepage := Some(url("https://github.com/daxten/autowire")),
developers ++= List(
Developer(
email = "[email protected]",
id = "lihaoyi",
name = "Li Haoyi",
url = url("https://github.com/lihaoyi")
) ,
Developer(
email = "[email protected]",
id = "daxten",
name = "Alexej Haak",
url = url("https://github.com/daxten")
)
)
).jsSettings(
resolvers ++= Seq(
"bintray-alexander_myltsev" at "http://dl.bintray.com/content/alexander-myltsev/maven"
),
scalaJSStage in Test := FullOptStage
resolvers ++= Seq(
"bintray-alexander_myltsev" at "http://dl.bintray.com/content/alexander-myltsev/maven"
),
scalaJSStage in Test := FullOptStage
).jvmSettings(
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/",
libraryDependencies ++= Seq(
// "org.scala-lang" %% "scala-pickling" % "0.9.1" % "test",
"com.esotericsoftware.kryo" % "kryo" % "2.24.0" % "test"
// "com.typesafe.play" %% "play-json" % "2.4.8" % "test"
),
libraryDependencies ++= {
if (!scalaVersion.value.startsWith("2.11.")) Nil
else Seq(
"org.scala-lang" %% "scala-pickling" % "0.9.1" % "test",
"com.typesafe.play" %% "play-json" % "2.4.8" % "test"
"com.typesafe.play" %% "play-json" % "2.5.15" % "test"
)
}
)

lazy val autowireJS = autowire.js
lazy val autowireJVM = autowire.jvm
lazy val autowireJVM = autowire.jvm
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.12
sbt.version=0.13.15
4 changes: 2 additions & 2 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
26 changes: 23 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Autowire 0.2.6
[![Build Status](https://travis-ci.org/Daxten/autowire.svg?branch=master)](https://travis-ci.org/Daxten/autowire)
[ ![Download](https://api.bintray.com/packages/daxten/maven/autowire/images/download.svg) ](https://bintray.com/daxten/maven/autowire/_latestVersion)

Autowire 0.3.1
==============

Autowire is a pair of macros that allows you to perform type-safe, reflection-free RPC between Scala systems. Autowire allows you to write type-safe Ajax/RPC calls that look like:
Expand Down Expand Up @@ -39,8 +42,14 @@ Getting Started
Autowire is available at the following maven coordinates, for Scala-JVM and Scala-JS respectively:

```scala
"com.lihaoyi" %% "autowire" % "0.2.6"
"com.lihaoyi" %%% "autowire" % "0.2.6"
resolvers in ThisBuild += Resolver.bintrayRepo("daxten", "maven")

// For jvm/js shared project
libraryDependencies += "de.daxten" %%% "autowire" % "0.3.1"

// or explicitly inside jvm/js
libraryDependencies += "de.daxten" %% "autowire" % "0.3.1"
libraryDependencies += "de.daxten" %%% "autowire" % "0.3.1"
```

It's only available for Scala.js 0.5.3+. Autowire works on both Scala-JVM and Scala-JS, meaning you can use it to get type-safe Ajax calls between a browser and your servers.
Expand Down Expand Up @@ -275,6 +284,17 @@ https://github.com/lihaoyi/workbench-example-app/tree/autowire
Changelog
=========

0.3.1
-----
- explicitly specify generic type of write calls in client macro (see https://github.com/lihaoyi/autowire/issues/59)


0.3.0
-----

- `.call()` now uses an implicit `ExecutionContext` (this helps your compiler/IDE)


0.2.6
-----

Expand Down