3

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 !

29er
  • 8,595
  • 12
  • 48
  • 65
  • What is you question? You don't know how to use `Observable.create()` or what? – martin Jul 26 '17 at 16:13
  • Yea, what type of Observable could I create here? Observable.of or Observable.from don't seem to fit my needs. is there an 'operator' that can use to create an observable where all i really need to 'next' is a completion ? – 29er Jul 26 '17 at 16:26

1 Answers1

1

SOLUTION: I was able to do something like

class myClass {
    constructor(){
    this.observer = null
}
   open(componentConfig){
        return Observable.create(obs => {
            this.observer = obs
        })
    }

close(closeArgs){
        this.observer.next(closeArgs)
        this.observer.complete()
    }

}

sorry if was original question was too vague

29er
  • 8,595
  • 12
  • 48
  • 65