try/finally with SBT tasks -


i have existing task called mytask, implementation don't control.

i want redefine in way: mytask := { val x = prepare() try mytask.value cleanup(x) }

as know, code wouldn't work, don't control when mytask.value executed.

prepare can called def.sequential(), , cleanup andfinally construct. problem how cleanup can return value of prepare().
def.sequential{ def.task{ prepare() }, mytask }.andfinally(cleanup(???))

one workaround use global variables, dirty hack.

any ideas?

related doc

i've tried use global variables, , works ok, though isn't elegant way implement it.

i have:

  • project/mytasks.scala
  • build.sbt

snippet in mytasks.scala:

object mytasks {    var x = option.empty[string]     def prepare(): string = ???    def cleanup(x: string): unit = ??? } 

snippet in build.sbt:

mytask := def.sequential{    def.task{       mytasks.x = some(mytasks.prepare())   },    mytask  }.andfinally {      mytasks.cleanup(mytasks.x.get)      mytasks.x = none }.value 

in way, can state prepare, , bypass sbt limitations.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -