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

fix tap and give it a consistent behaviour #138

Closed
Xavier-Redondo opened this issue Feb 27, 2024 · 0 comments
Closed

fix tap and give it a consistent behaviour #138

Xavier-Redondo opened this issue Feb 27, 2024 · 0 comments
Labels
bautajs-core enhancement New feature or request

Comments

@Xavier-Redondo
Copy link
Contributor

Xavier-Redondo commented Feb 27, 2024

The current implementation of tap decorator had issues.

First issue: it was not really fit to purpose, especially when trying to use asyncrhonous functions as input (it did not work and when there was timeouts or rejected promises involved, literally it could crash or cause bad behaviour).

Second issue: Its definition when implemented was not consistent with the canonical definition of tap (which never parallelizes and it works as a way to eenable side effects to the main flow of the pipeliines)

Third issue: it was not multi parameter, now it can support as a pipeline various step functions

Basically the reason of this issue and the related pr is to enable a pattern that we have been using that involves asynchronous validations.

Currently we have to use a pattern using pairwise that is cumbersome, the option to use tap would simplify the code, because instead of using something like this:

pipe(
  getFirstObjectFromRequestStep(),
  pairwise(asynchronousValidationWithPreviousObjectStep(),
  [firstObject,...nothingUsefulHere] => firstObject,
  anotherStepThatUsesTheFirstObjectStep()
)

You can see that using pairwise here is cumbersome because we have to add an artificial step only to map the object that comes in an array from pairwise, that is only used to not lose the reference to the original object in the previous step (Which is not the original target use case for pairwise decorator).

instead, with tap we should be able to do this:

pipe(
  getFirstObjectFromRequestStep(),
  tap(asynchronousValidationWithPreviousObjectStep(),
  anotherStepThatUsesTheFirstObjectStep()
)

tap either returns the first object received by the first step, or an exception if it has been thrown inside any step function inside the decorator tap.

if you want to know details about tap definition you can check here or here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bautajs-core enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants