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

Future vs Lazy #1

Open
cristianoc opened this issue May 20, 2018 · 1 comment
Open

Future vs Lazy #1

cristianoc opened this issue May 20, 2018 · 1 comment

Comments

@cristianoc
Copy link

Is it correct to think about the current implementation as lazy evaluation, in that functions are delayed and executed on demand, rather than started asynchronously?

@gilbert
Copy link
Member

gilbert commented May 21, 2018

Good question! This lib behaves like promises in the fact that they are executed as soon as you make one. In other words...

Future.make(resolve => {
  Js.log("executing!");
  resolve(10)
})

...will log "executing!" immediately, even if you never call Future.map or Future.get.

Why strictness? I went down a rabbit hole of researching the pros and cons of lazy vs strict, how JS promises might have benefitted if they were lazy instead, and even implemented lazy as a first draft. However, the only use case I could find for pro-lazy was "async data loading with a dependency graph". There might be more, but for the common case, strict is more convenient than lazy, and it's easy enough to go lazy when you need to by writing a simple thunk like let makePromise = (args) => new Promise(...).

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

2 participants