-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve : Use scala.concurrent.Future instead of custom callback func…
…tion. 1. Now all asynchronous APIs return Future object. You can use it to return as Web response in Play!. 2. Wrap asynchronous functions with API.sync if you want to run APIs synchronously. See Application.sync.
- Loading branch information
kangmo
committed
May 5, 2014
1 parent
a5d92ec
commit 99effea
Showing
11 changed files
with
485 additions
and
280 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
@(message: String) | ||
|
||
@main("Welcome to Play") { | ||
|
||
@play20.welcome(message) | ||
|
||
<p> | ||
<a href="@routes.Application.async">Run Asynchronous API Examples</a> | ||
</p> | ||
<p> | ||
<a href="@routes.Application.sync">Run Synchronous API Examples</a> | ||
</p> | ||
} |
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
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,44 @@ | ||
package org.kangmo.tradeapi | ||
|
||
import org.kangmo.http._ | ||
import org.kangmo.helper._ | ||
|
||
import java.math.BigDecimal | ||
import scala.concurrent._ | ||
|
||
abstract class AbstractChannel() { | ||
def getPublicFuture[T : Manifest](resource : String) : Future[T] = { | ||
val p = promise[T] | ||
|
||
HTTPActor.dispatcher ! GetPublicResource(resource) { jsonResponse => | ||
val obj : T = Json.deserialize[T](jsonResponse) | ||
p success obj | ||
} | ||
|
||
p.future | ||
} | ||
} | ||
|
||
abstract class AbstractUserChannel(context : Context) { | ||
def getUserFuture[T : Manifest](resource : String) : Future[T] = { | ||
val p = promise[T] | ||
|
||
HTTPActor.dispatcher ! GetUserResource(context, resource) { jsonResponse => | ||
val obj : T = Json.deserialize[T](jsonResponse) | ||
p success obj | ||
} | ||
|
||
p.future | ||
} | ||
|
||
def postUserFuture[T : Manifest](resource : String, postData : String) : Future[T] = { | ||
val p = promise[T] | ||
|
||
HTTPActor.dispatcher ! PostUserResource(context, resource, postData) { jsonResponse => | ||
val obj : T = Json.deserialize[T](jsonResponse) | ||
p success obj | ||
} | ||
|
||
p.future | ||
} | ||
} |
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
Oops, something went wrong.