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

Support selector finally function. #89

Open
izaakschroeder opened this issue Aug 17, 2018 · 1 comment
Open

Support selector finally function. #89

izaakschroeder opened this issue Aug 17, 2018 · 1 comment

Comments

@izaakschroeder
Copy link
Contributor

There are sometimes resources attached to a connection that need cleaning up – e.g. database connection that's been checked out from a pool.

createSelector(getA, getB, getC, async (a, b, c) => {
  return await dbPool.checkout(); // how to clean up this connection?
});

Possible option:

createSelector(getA, getB, getC, async (a, b, c) => {
  return await dbPool.checkout();
}).withDisposer(async (a, b, c, con) => {
  return await dbPool.release(con);
});
@izaakschroeder
Copy link
Contributor Author

izaakschroeder commented Aug 30, 2018

NOTE: I think this could be solved with Observable. See: https://github.com/tc39/proposal-observable.

Something like

createSelector(() => {
  return new Observable(observer => {
    const connection = await dbPool.checkout();
    next(connection);
    return () => {
      connection.release();
    };
});

Something similar for creating the dbPool object itself as well.

const dbPool = new Observable(observer => {
  const dbPool = ...;
  next(dbPool);
  return () => {
    await dbPool.end();
  };
});

Except the difference here being the observe would trigger on server creation and shutdown instead of on request.

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

No branches or pull requests

1 participant