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

in route handler, buffer synchronous observable emissions #222

Open
jameslaneconkling opened this issue Jul 25, 2018 · 0 comments
Open

in route handler, buffer synchronous observable emissions #222

jameslaneconkling opened this issue Jul 25, 2018 · 0 comments

Comments

@jameslaneconkling
Copy link

The following router implementation using observables produces inefficient, disaggregated service calls

const router = new Router([
    {
      route: 'people[{integers:indices}]',
      get: ({ indices }) => {
        return from(indices).pipe(
          map((index) => ({
            path: ['people', index],
            value: { $type: 'ref', value: ['peopleById', `_${index}`] }, // fake index -> id mapping
          }))
        );
      },
    },
    {
      route: 'peopleById[{keys:ids}].name',
      get: ({ ids }) => {
        console.log('ids', ids);
        return from(ids).pipe(
          map((id) => ({
            path: ['peopleById', id, 'name'],
            value: `Person #${id}`,
          }))
        );
      },
    }
]).subscribe();

// > ids [ '_1' ]
// > ids [ '_2' ]
// > ids [ '_3' ]
// > ids [ '_4' ]
// > ids [ '_5' ]

Adding a bufferTime(0) operator correctly keeps synchronous emissions aggregated

const router = new Router([
    {
      route: 'people[{integers:indices}]',
      get: ({ indices }) => {
        return from(indices).pipe(
          map((index) => ({
            path: ['people', index],
            value: { $type: 'ref', value: ['peopleById', `_${index}`] },
          })),
          bufferTime(0),
        );
      },
    },
    ...
]).subscribe();

Should buffering of synchronous observable responses be the default?

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

No branches or pull requests

1 participant