Use Observable for a one time event

Viewed 627

I have 2 functions ( for simplicity, open/close ):

open(config){
    ...do something
    this.watchForClosing = Observable.create(..?..)
    return this.watchForClosing
}

close(closeArgs){
    this.watchForClosing.complete(closeArgs)
}

What i am trying to achieve is a calling method that works like this:

myClass.open(myData)
.subscribe( closeArgs => console.log('closed'))

Basically I want the calling function to call the open function and get a 'callback' when the close function has been called, and am struggling on how to create an Observable that will do this. thanks for any guidance !

1 Answers
Related