I have a resource object stored in an option.
private var ochan: Option[Channel] = None
At some point during program execution, ochan
is set to Some(channel)
. I'd like to close the channel (via invoking the method close
) and set the option to None
in one fatal swoop.
Currently I have:
def disconnect = ochan = { ochan.foreach{_.close}; None }
And previously I had:
def disconnect = ochan = ochan.flatMap{ o => o.close; None }
Is there a better way to do this?