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.map can apply function more than once #32

Closed
osyvokon opened this issue Nov 8, 2013 · 1 comment
Closed

Future.map can apply function more than once #32

osyvokon opened this issue Nov 8, 2013 · 1 comment
Assignees
Labels
Milestone

Comments

@osyvokon
Copy link

osyvokon commented Nov 8, 2013

Let r be a result of Future.map call. Its type is Future. When I call r.get() multiple times, it will recompute its value that many times. This behavior differs from ordinary "non-map" Futures which cache computed value.

Failing unit-test for illustration:

def test_map_computes_each_value_only_once(self):
    def f(x):
        f.calls_count += 1
    f.calls_count = 0

    future = self.results[0].map(f)
    self.results[0].set(30)
    future.get(timeout=0)
    future.get(timeout=0)

    self.assertEqual(f.calls_count, 1)

To recap, two problems here:

  1. Mapped function call can be expensive, for example, it can start new actors.
  2. Future.get() semantics differs for Futures obtained with map and ask.

Same issue applies to filter/reduce.

@jodal
Copy link
Owner

jodal commented Nov 9, 2013

Confirmed. Will fix in the next release.

@ghost ghost assigned jodal Nov 16, 2013
@jodal jodal modified the milestone: v1.3 Jan 27, 2016
@jodal jodal closed this as completed in cdeefce Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants