continuations

Why does the OnlyOnCanceled continuation get called?

元气小坏坏 提交于 2021-02-05 07:23:10
问题 When calling await RunAsync(); on the below code, I would expect the continuation with TaskContinuationOptions.OnlyRanToCompletion continuation to run, however the OnlyOnCanceled continuation gets called (yielding the debug output "Task canceled"). Why? private static async Task RunAsync() { try { await Task.Run(() => DoWork()) .ContinueWith( (t) => { if (t?.Exception != null) { throw t.Exception; } }, TaskContinuationOptions.OnlyOnFaulted ).ContinueWith( (t) => { Debug.WriteLine("Task

Execute the following call/cc expression

孤人 提交于 2020-01-14 04:34:27
问题 I use racket and I got the result 4 for following simple code: (let/cc done ((let/cc esc (done (+ 1 (let/cc k (esc k))))) 3)) and I was going to execute this code step-by-step. First, I changed the first let/cc into the form of call/cc like below: (call/cc (λ (done) ((let/cc esc (done (+ 1 (let/cc k (esc k))))) 3))) Of course, this produces 4 also. Second, since I found the mechanism of call/cc in the internet which says call/cc do following 4 steps: Captures the current continuation.

Correct terminology for continuations

二次信任 提交于 2020-01-12 13:01:07
问题 I've been poking around continuations recently, and I got confused about the correct terminology. Here Gabriel Gonzalez says: A Haskell continuation has the following type: newtype Cont r a = Cont { runCont :: (a -> r) -> r } i.e. the whole (a -> r) -> r thing is the continuation (sans the wrapping) The wikipedia article seems to support this idea by saying a continuation is an abstract representation of the control state of a computer program. However, here the authors say that Continuations

Multiple Task Continuation

丶灬走出姿态 提交于 2020-01-05 08:38:24
问题 I would like to understand this scenario a little clearer: Consider the following code: frmProgressAsync prog = new frmProgressAsync(true); TaskWithProgress t = new TaskWithProgress("Smoothing CP", true); t.Task = A.ShowMovingAverage(tension,t.Progress) .ContinueWith(prev => { t.ProgressInformation.Report("Smoothing FG"); B.ShowMovingAverage(tension, t.Progress); }); await prog.RunAsync(t); I have two tasks I wish to run A.ShowMovingAverage and B.ShowMovingAverage . Both return a Task. In the

How to use continuations in scheme?

淺唱寂寞╮ 提交于 2020-01-05 04:56:10
问题 I'm trying to understand call/cc operator in Scheme. I'm planing of implementing this in my JavaScript lisp. This is my simple code: (letrec ((x 0) (f (lambda (r) (set! x r) (display (r 20)) (display "10")))) (display (call/cc f)) (x "30")) I tough that it should print 20 then 30 then 10. But it create infinite loop (it keep printing 30). How this code should look like to display 3 values, call display 3 times? Should it be possible to create loops that don't consume stack with continuations?

Seasoned Schemer's get-first, get-next, and waddle functions

你。 提交于 2020-01-02 05:06:05
问题 (define get-first (lambda (l) (call-with-current-continuation (lambda (here) (set! leave here) (waddle l) (leave (quote ())))))) (define get-first (lambda (l) (call-with-current-continuation (lambda (here) (set! leave here) (leave (waddle l)))))) For anybody not familiar with the book "The Seasoned Schemer", get-first , get-next , and waddle (last two not defined here) are procedures to apparently model coroutines to iterate through a tree passed to waddle that yields leaves only. Just prior

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

廉价感情. 提交于 2020-01-02 03:34:12
问题 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

SICP, Continuation Passing Style and Clojure's trampoline

╄→гoц情女王★ 提交于 2020-01-01 19:19:09
问题 I am working with SICP and exercise 2.29-b gave me the opportunity to have fun with the Continuation Passing Style while traversing mobiles and branches. To make the story short, each mobile has left and right branch, which are composed by a length and either a numeric weight or another mobile. The question asks to find the total weight given a mobile. After the first mutually recursive solution, quite simple, I tried and successfully implemented a cps' one: (defn total-weight-cps [mobile]

Scala: Delimited Continuations Explained - Not

主宰稳场 提交于 2020-01-01 06:56:58
问题 Interested in the concept of continuation, I started reading wikis, posts, and came to this "simple" example: reset { ... shift { k: (Int=>Int) => // the continuation k will be the '_ + 1' below k(7) } + 1 } // result: 8 Without knowledge of Scala, I'm totally lost here, could not figure out how the 8 comes out. Below is how I tried to figure out the meaning but failed. Any guy could you please give me a short explanation? Yeah there are Scala grammar books but they are too thick, I'm more