continuations

Is ContinueWith guaranteed to execute?

早过忘川 提交于 2019-12-07 03:16:43
问题 I've got a bit of code that is acting as a light weight, non-blocking, critical section. I am hoping that no matter what happens with _func and cancellationToken in the Task.Run clause, that the continuation is guaranteed to run such that the Exit statement in its finally block will always execute. Is it safe to assume that the finally block below, short of catastrophic failure in the process, will be executed with roughly the same guarantees that finally normal operates with? if (Enter()) {

How GOTO statement in Groovy?

社会主义新天地 提交于 2019-12-06 06:49:48
问题 I saw this nice blog post about a Scala continuations that 'emulates' a GOTO statement in the Scala language. (read more about Continuations here) I would like to have the same in the programming language Groovy. I think it's possible within a Groovy compiler phase transformation. I'm working on an Domain-Specific Language (DSL), and preferred embedded in Groovy. I would like to have the GOTO statement, because the DSL is an unstructured language (and is generated from workflow diagrams). I

What are “Jetty 6 Continuations” and how do they compare to the continuations found in programming languages?

十年热恋 提交于 2019-12-06 06:17:50
I'm looking for an answer that describes a "continuation" mechanism in a web server vs. a programming language. My understanding is that using continuations, it is trivial to have a "digits of pi" producer communicate with a "digits of pi" consumer, without explicit threading. I've heard very good things about Jetty continuations. I am curious what others think. I may have already found my answer, but I'm asking the question here anyway - for the record. how do they compare to the continuations found in programming languages? They have nothing in common apart from the name. It's merely a

Scala Continuations - Why can't my shifted call be inside a try-catch block?

╄→гoц情女王★ 提交于 2019-12-06 05:06:26
问题 I'm new to Scala continuations, and relatively new to the scala language in general. I tried playing with Scala continuations and wrote the following code: case class MyException(msg:String) extends Exception def go:Int = reset { println("enter your input") val my_check = //try { val user_input = readLine() if (!user_input.matches("\\w+")) { throw new MyException("illegal string: " + user_input) } shift { k: (Boolean => Int) => { if (user_input == "true") { k(true) } else if (user_input ==

How does Smalltalk manipulate call stack frames (thisContext)?

故事扮演 提交于 2019-12-06 03:38:57
问题 The Smalltalk object thisContext look strange and marvelous. I can't understand what it is and how it works. And even how it enables continuations. For C's call-stack, I can easily imagine how is it implemented and working. But for this... I can't. Please help me to understand it. 回答1: I think it is not an easy question. The stack is reified in the image with instances of MethodContext. A MethodContext can have a sender, which is another MethodContext. That one can have another one..

Understanding Haskell callCC examples

大兔子大兔子 提交于 2019-12-06 03:33:12
问题 I am having trouble understanding the answers to a previous question. I'm hoping that an explanation of the following will clarify things. The following example comes from fpcomplete import Control.Monad.Trans.Class import Control.Monad.Trans.Cont main = flip runContT return $ do lift $ putStrLn "alpha" (k, num) <- callCC $ \k -> let f x = k (f, x) in return (f, 0) lift $ putStrLn "beta" lift $ putStrLn "gamma" if num < 5 then k (num + 1) >> return () else lift $ print num The output is alpha

What do “continuations” mean in functional programming?(Specfically SML)

梦想的初衷 提交于 2019-12-05 14:08:32
I have read a lot about continuations and a very common definition I saw is, it returns the control state. I am taking a functional programming course taught in SML. Our professor defined continuations to be: "What keeps track of what we still have to do" ; "Gives us control of the call stack" A lot of his examples revolve around trees. Before this chapter, we did tail recursion. I understand that tail recursion lets go of the stack to hold the recursively called functions by having an additional argument to "build" up the answer. Reversing a list would be built in a new accumulator where we

Different kinds of continuations in Racket

╄→尐↘猪︶ㄣ 提交于 2019-12-05 11:17:31
Can someone give a relatively simple example of the differences in Racket between call-with-composable-continuation and call-with-current-continuation . I've worked through the examples in the Racket Guide 10.3 of call-with-composable-continuation , and the examples of call-with-current-continuation in The Scheme Programming language section 3.3 but I'm not clear on the difference. Could someone give an example where they would give different results in the same context. A very thorough explanation is found in the paper "Adding Delimited and Composable Control to a Production Programming

Use Spring Web Flow without state on the server

两盒软妹~` 提交于 2019-12-05 10:26:40
I'm reading the Spring Web Flow chapter in the book Pro Spring MVC. Unfortunately there's no explicit information, where the state during a flow execution is persisted. I assume it is saved in the JVM Heap and associated with the session. Now HTTP is a stateless protocol (REST...) and I'd like to use Spring Web Flow without saving state on the server (besides the one and only state that a session might be authenticated). One strategy is to send all parameters of the entire flow with every HTTP request of the flow (hidden input) and thus accumulating all necessary parameters until the flow has

async/await vs. hand made continuations: is ExecuteSynchronously cleverly used?

∥☆過路亽.° 提交于 2019-12-05 06:44:54
I recently wrote the following code: Task<T> ExecAsync<T>( string connectionString, SqlCommand cmd, Func<SqlCommand, T> resultBuilder, CancellationToken cancellationToken = default(CancellationToken) ) { var tcs = new TaskCompletionSource<T>(); SqlConnectionProvider p; try { p = GetProvider( connectionString ); Task<IDisposable> openTask = p.AcquireConnectionAsync( cmd, cancellationToken ); openTask .ContinueWith( open => { if( open.IsFaulted ) tcs.SetException( open.Exception.InnerExceptions ); else if( open.IsCanceled ) tcs.SetCanceled(); else { var execTask = cmd.ExecuteNonQueryAsync(