Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when reusing default instance #37

Open
andrewryan1906 opened this issue Nov 26, 2019 · 1 comment
Open

Issue when reusing default instance #37

andrewryan1906 opened this issue Nov 26, 2019 · 1 comment

Comments

@andrewryan1906
Copy link

andrewryan1906 commented Nov 26, 2019

I'm using PubNub in conjunction with AWS Step Functions to observe a step function during execution. I have two step functions; Step Function A and Step Function B.

When I run function A, everything works OK; I get all of the PubNub communications. However, when I run function B, I get nothing. This is the code I'm using inside of my step function poling service:

  constructor(private stepFunctionsService: StateMachinesService, private securityService: SecurityService, private pubNub: PubNubAngular) {
  }

 
  WaitForStepFunctionExecutionToComplete<T>(token: StepFunctionExecutionToken, progressSubject$?: Subject<StepFunctionProgressMessage>): Observable<T> {


    if (token.notification_channel && progressSubject$) {
      console.log('Initializing PubNub');
      this.pubNub.init({
        publishKey: token.notification_publishKey,
        subscribeKey: token.notification_subscribeKey
      });

      this.pubNub.subscribe({
        channels: [token.notification_channel],
        triggerEvents: ['message']
      });
      this.pubNub.getMessage(token.notification_channel, msg => {

        return progressSubject$.next(msg.message);
      });

    }

So, once I kick off a step function, I run the pubNub.init() method. The first time, it works fine; the second time, it won't reset/reinitialize the instance.

What am I doing wrong? How can I get the default pubNub instance to "reset," so I can use it with other channels/instances?

@colonelpopcorn
Copy link

Per the documentation, you are not really supposed to deinitialize or create a new pubnub instance. You should probably just use separate channels and a singleton service.

https://www.pubnub.com/docs/angular2-javascript/pubnub-javascript-sdk#inject-pubnub-angular2
https://angular.io/guide/singleton-services

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants