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

Compiler: better support for promise chains #800

Open
josephjclark opened this issue Oct 21, 2024 · 0 comments
Open

Compiler: better support for promise chains #800

josephjclark opened this issue Oct 21, 2024 · 0 comments

Comments

@josephjclark
Copy link
Collaborator

Did we miss a trick with promise chains? Should we be able to support an operation inside a .then callback?

We can currently do this:

each(
  $.items,
  post(`patient/${$.data.id}`, $.data).then(state => {
    state.completed.push(state.data);
    return state;
  })
);

But surely it would be cool to support this?

each(
  $.items,
 get(`patient/${$.data.id}`)
   .then(post(`patient/${$.data.id}`, $.data))
   .then((state => {
    console.log('done!')
    return state
  })
)

What I'm saying is that inside then() we should be able to write an operation, without a ()(state) wrapper.

Either compiler code, or some magic in promises (perhaps even a custom promise library), would have to "unwrap" the operation.

Something like this maybe?

each(
  $.items,
 get(`patient/${$.data.id}`)
   .then((state) => post(`patient/state{state.data.id}`, state.data)(state))
   .then((state => {
    console.log('done!')
    return state
  })
)

But my feeling is:

  • .then() is called with state
  • .then(get()) will pass a function into .then(), which will be lazily executed
  • Can we extend .then() to recognise that an Operation has been passed in, and handle it appropriately? I should have all the information it needs.
@github-project-automation github-project-automation bot moved this to New Issues in v2 Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New Issues
Development

No branches or pull requests

1 participant