@@ -147,29 +147,32 @@ object AsynchronousIo {
147147 }
148148 }
149149
150- private def completionHandler [Value ](successHandler : Value => (Unit !! Throwable )) = {
151- new CompletionHandler [Value , Throwable => Unit ] {
152- def failed (exc : Throwable , failureHandler : Throwable => Unit ): Unit = {
153- failureHandler(exc)
154- }
150+ given [Domain , Value ](using
151+ fenceDsl : Dsl .Searching [Fence .type , Domain , Unit ],
152+ liftUnit : Dsl .Lift [Unit , Domain ]
153+ ): Dsl .Original [AsynchronousIo [Value ], Domain , Value ] =
154+ Dsl .Original { (keyword, handler) =>
155+ liftUnit(
156+ keyword.start(
157+ handler,
158+ new CompletionHandler [Value , Value => Domain ] {
159+ def failed (
160+ exception : Throwable ,
161+ handler : Value => Domain
162+ ): Unit = {
163+ fenceDsl(Fence , (_ : Unit ) => throw exception)
164+ }
155165
156- def completed (result : Value , failureHandler : Throwable => Unit ): Unit = {
157- val protectedContinuation =
158- try {
159- successHandler(result)
160- } catch {
161- case NonFatal (e) =>
162- val () = failureHandler(e)
163- return
166+ def completed (
167+ result : Value ,
168+ handler : Value => Domain
169+ ): Unit = {
170+ fenceDsl(Fence , (_ : Unit ) => handler(result))
171+ }
164172 }
165- protectedContinuation(failureHandler)
166- }
167- }
168- }
173+ )
174+ )
169175
170- given [Value ]: Dsl .Original [AsynchronousIo [Value ], Unit !! Throwable , Value ] =
171- Dsl .Original { (keyword, handler) =>
172- keyword.start(_, completionHandler(handler))
173176 }
174177
175178}
0 commit comments