-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Remote Config acknowledgements to be async (#4638)
Remote Config updates coming from the Agent needs to be acknowledged. This PR changes the existing behavior by optionally allowing the acknowledgement to be async. This is achieved by: - Changing the way you register products from using the `EventEmitter` API to a custom API that only allows a single handler per product (event emitters can have more than one listener, which is problematic as we can't support more than one of the listeners to acknowledge the config). The new API is as follows: - `rc.setProductHandler(product, handler)` (prevously `rc.on(product, handler)`) - `rc.removeProductHandler(product)` (prevously `rc.off(product, handler)`) - The new product handler is called similar to the old event listener, with the following exception: A new optional 4th argument is supplied called `ack`. This is a callback which can be called (sync or async) either without any arguments (to set the state to `ACKNOWLEDGED`) or with a single error argument (to set the state to `ERROR`). - If the handler function signature takes less than 4 arguments or doesn't use the rest operator (`...args`), and... - ...the handler doesn't return a `Promise`: The state is set to `ACKNOWLEDGED` right away without the handler having to do anything (existing behavior) - ...the handler returns a `Promise`, we wait until the promise is resolved or rejected and set the state accordingly (new behavior) - If the handler function signature takes 4 or more arguments or use the rest operator (`...args`): The state is left as `UNACKNOWLEDGED` until the `ack` callback is called (new behavior) - In any case, the state is still set to `ERROR` if the handler throws (existing behavior) The `RemoteConfigManager` is still an `EventEmitter` however because the `kPreUpdate` symbol is still being emitted.
- Loading branch information
Showing
7 changed files
with
232 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.