I started from this code and I enhanced it to look like my previous post for Kotlin.
find this code in https://github.com/spointeau/scala-using-autoClose/blob/master/MainUsing.scala
I also did re-implement the .use{} that I generally use in Kotlin when I deal with only 1 or 2 resources max. The implementation was so simple by reusing the autoClose. You can find the code in the same github file.
test1
Close test2
May 13, 2018 1:04:27 AM arm$using$ $anonfun$apply$1
WARNING: Close Exception test2
Close test1
java.lang.Exception: Close Exception test1
at TestToClose.close(MainUsing.scala:166)
at arm$using$.$anonfun$apply$1(MainUsing.scala:119)
at arm$using$.$anonfun$apply$1$adapted(MainUsing.scala:117)
at scala.collection.immutable.List.foreach(List.scala:389)
at arm$using$.apply(MainUsing.scala:117)
at MainUsing$.delayedEndpoint$MainUsing$1(MainUsing.scala:177)
at MainUsing$delayedInit$body.apply(MainUsing.scala:173)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at MainUsing$.main(MainUsing.scala:173)
at MainUsing.main(MainUsing.scala)
test3
Close test3
test4
Close test4
java.lang.Exception: Close Exception test4
at TestToClose.close(MainUsing.scala:166)
at arm$using$.$anonfun$apply$1(MainUsing.scala:119)
at arm$using$.$anonfun$apply$1$adapted(MainUsing.scala:117)
at scala.collection.immutable.List.foreach(List.scala:389)
at arm$using$.apply(MainUsing.scala:117)
at arm$AutoCloseResource$.use$extension1(MainUsing.scala:152)
at arm$AutoCloseResource$.use$extension0(MainUsing.scala:150)
at MainUsing$.delayedEndpoint$MainUsing$1(MainUsing.scala:193)
at MainUsing$delayedInit$body.apply(MainUsing.scala:173)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at MainUsing$.main(MainUsing.scala:173)
at MainUsing.main(MainUsing.scala)
did it help you?
Aucun commentaire:
Enregistrer un commentaire