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

chore: improve Listener signature #1826

Merged
merged 1 commit into from Mar 5, 2020
Merged

Conversation

hacksparrow
Copy link
Contributor

@hacksparrow hacksparrow commented Mar 3, 2020

Improved Listener signature so it can accept callback or promise.

Addresses https://github.com/strongloop/loopback-next/pull/4730/files#r385912758, required for landing PR loopbackio/loopback-next#4730.

The observe and removeObserver methods of a class implementing ObserverMixin can accept a callback or a promise. The current typing does not allow that. This PR re-defines the Listener type to be either a callback that returns void or a promise that resolves to void.

The problem this PR solves manifests only in TS projects, like LB next, hence it cannot be tested in the Juggler repository.

Before settling on this change, we tried another approach:

export interface Listener<Ctx = OperationHookContext<typeof ModelBase>> {
  (ctx: Ctx, next: (err?: any) => void): void;
  (ctx: Ctx): Promise<void>;
}

but the overloaded interfaced did not work as expected.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

Improved Listener signature so it can accept callback or promise.
@agnes512
Copy link
Contributor

agnes512 commented Mar 4, 2020

@slnode test please

Copy link
Contributor

@agnes512 agnes512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope jenkins passes

@hacksparrow
Copy link
Contributor Author

@agnes512 @dhmlau Jenkins failing due to an un-related issue.

20:37:21 
20:37:21   ․․․․Connection fails: Error: connect ECONNREFUSED 127.0.0.1:4
20:37:21 It will be retried for the next request.
20:37:21 ․․․[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6
20:37:22     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
20:37:22 ․,,․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․,,․․․․․․․․․!
20:37:26 
20:37:26   48 passing (6s)
20:37:26   4 pending
20:37:26 
  1 failing
20:37:26 
20:37:26   1) "before each" hook: clearDatabase for "works for Date values":
20:37:26      Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

@hacksparrow hacksparrow merged commit 2946c5b into master Mar 5, 2020
@delete-merged-branch delete-merged-branch bot deleted the improve-listener-signature branch March 5, 2020 09:00
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

Successfully merging this pull request may close these issues.

None yet

5 participants