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

[Suggestion] If the continue 'Callback' is called last, send it as a response anyway. #12

Open
Danappelxx opened this issue Sep 26, 2015 · 5 comments
Assignees

Comments

@Danappelxx
Copy link
Collaborator

Basically if I were to have this:

mast.server.get("/") { req, res, cb in
            res.bodyString = "Hello!"
            cb(.Continue(req,res))
}

currently, Taylor would return a not found page. I propose adding detection which correct the .Continue to .Send if its the last one.

@perezpaya
Copy link
Collaborator

@Danappelxx I'll have a look into it! Thanks man!

@izqui
Copy link
Owner

izqui commented Sep 30, 2015

The problem with this right now, is that as we rely on the callback in order to make it async, the only way to do that would be to have some kind of timeout for each handler.

Thinking a lot about whether the callback thing is worth it vs just returning the request and response at the end of the closure.

typealias Handler = (Request, Response) -> (Request, Response)

or even

typealias Handler = (inout Request, inout Response) -> Void

but I'm not very confident with the last one

@perezpaya
Copy link
Collaborator

I belive we could try with something like this
screen shot 2015-09-30 at 11 22 14
Tell me what do you think about it

@Danappelxx
Copy link
Collaborator Author

The timeout solution seems really dirty to me since it would create a delay if a continue is indeed the last callback, and it would also get in the way if you have a long-running operation.

Perhaps you could use promises internally? I know promisekit has a useful method called when that waits for a set of promises to complete and afterwards performs an action. The example they provide is:

let search1 = MKLocalSearch(request: rq1).promise()
let search2 = MKLocalSearch(request: rq2).promise()

when(search1, search2).then { response1, response2 in
    //...
}

I don't think it would be too hard to port it to fit Taylor's needs.

@Danappelxx
Copy link
Collaborator Author

Alright - if nobody else will I'll play around with this when I can find the time :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants