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

Enhance Event Emitter to ignore events generated by same process ID #2279

Open
t1m0thyj opened this issue Sep 27, 2024 · 1 comment
Open
Labels
enhancement New feature or request priority-medium Not functioning - next quarter if capacity permits

Comments

@t1m0thyj
Copy link
Member

Is your feature or enhancement request related to a problem or limitation? Please describe

As a developer of a Zowe app like Zowe Explorer that uses the Imperative event emitter, I register the ON_VAULT_CHANGED event because I want to know when an external app has updated credentials. The event also fires when my own app has updated credentials, which is not ideal as it may result in a duplicate refresh operation (e.g. the "Update Credentials" dialog shows twice).

Describe your enhancement idea

Add an ignoreSameProcess option when registering to watch for an event, which checks the PID (process ID) of the event and prevents events from being emitted to the same app that triggered them.

Describe alternatives you've considered

An alternative workaround is for apps like ZE to modify the EventProcessor prototype to skip duplicate events, but this is kind of hacky:

const oldEmitZoweEvent = (imperative.EventProcessor.prototype as any).emitZoweEvent;
(imperative.EventProcessor.prototype as any).emitZoweEvent = function (eventName: string): void {
    if (eventName === imperative.ZoweUserEvents.ON_VAULT_CHANGED) {
        Constants.IGNORE_VAULT_CHANGE = true;
    }
    oldEmitZoweEvent.call(this, eventName);
};
imperative.EventOperator.getWatcher().subscribeUser(imperative.ZoweUserEvents.ON_VAULT_CHANGED, async () => {
    if (Constants.IGNORE_VAULT_CHANGE) {
        Constants.IGNORE_VAULT_CHANGE = false;
        return;
    }
    // Handle event here
});

Provide any additional context

Related to this Zowe Explorer PR: zowe/zowe-explorer-vscode#3157

@t1m0thyj t1m0thyj added enhancement New feature or request new The issue wasn't triaged yet labels Sep 27, 2024
Copy link

Thank you for raising this enhancement request.
The community has 90 days to vote on it.
If the enhancement receives at least 5 upvotes, it is added to our development backlog.
If it receives fewer votes, the issue is closed.

@JTonda JTonda added priority-medium Not functioning - next quarter if capacity permits and removed new The issue wasn't triaged yet labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority-medium Not functioning - next quarter if capacity permits
Projects
Status: Medium Priority
Development

No branches or pull requests

2 participants