Question about evaluation order

7 views
Skip to first unread message

Akira Hayakawa

unread,
Sep 9, 2015, 4:22:51 AM9/9/15
to spray.io User List
Hi,

I found a very weird behavior. I am using 1.3.3

In the code below, I have three line under noop ~ get with each grouped in either A or B.

If we choose group A the output is

Options
Get
hoge

but with the another group we get

hogeOptions
Get


It sounds to me although they are of the same abstraction Directive the effect on routing order is different in a way group A evaluates the inner route lazily and the other does eagerly. How could you explain this?

I found this behavior while I am doing an experiment to solve my problem about unexpected routing behavior. My expectation is the matching is done from the forefront and enter the inner route immediately once it matches the "options" without evaluating anything behind. So I expect the behavior of extract as the noop.


class SprayRoutingTest extends FunSuite with ScalatestRouteTest with HttpService {
def actorRefFactory = system

val route = TestRouter().route

test("Options") {
println("Options")
Options("/") ~> route ~> check {
assert(status === StatusCodes.Forbidden)
}
}

test("Get") {
println("Get")
Get("/") ~> route ~> check {
assert(status === StatusCodes.OK)
}
}
}

case class TestRouter() extends SimpleRoutingApp {
val route =
options {
complete(StatusCodes.Forbidden)
} ~ noop {
get {
extract(_.request) { req => // (A)
//provide(0) { n => // (B)
//noop { // (B)
println("hoge")
complete(StatusCodes.OK)
}
}
}
}

- Akira

Akira Hayakawa

unread,
Sep 9, 2015, 4:37:20 AM9/9/15
to spray.io User List
Oh sorry,

I should have read this article. If I still have questions after understanding this I will resend questions

- Akira

Johannes Rudolph

unread,
Sep 9, 2015, 4:39:50 AM9/9/15
to spray...@googlegroups.com
+1 :)

Also, try looking in the archives of this group. If you search for
this URL you should find a lot more information about the topic.

Johannes
> --
> You received this message because you are subscribed to the Google Groups
> "spray.io User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to spray-user+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spray-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/spray-user/c65ea2f7-26f3-49e6-a732-64d50f4fbe68%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Reply all
Reply to author
Forward
0 new messages