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

What's the reason updateAction API doesn't allow modifiction? #535

Closed
nanonaren opened this issue Apr 20, 2016 · 10 comments
Closed

What's the reason updateAction API doesn't allow modifiction? #535

nanonaren opened this issue Apr 20, 2016 · 10 comments

Comments

@nanonaren
Copy link
Contributor

Is there any particular reason for Control.AutoUpdate.updateAction not providing an API to update the existing value? Seems rather a useful thing to have to me.

@nanonaren nanonaren changed the title What's the reason updateAction API doesn't modifiction? What's the reason updateAction API doesn't allow modifiction? Apr 20, 2016
@snoyberg
Copy link
Member

Can you clarify what kind of API you're looking for, ideally with a type signature?

@nanonaren
Copy link
Contributor Author

So, I was looking for something like the following

updateAction :: Maybe a -> IO a

That way, when run run the first time it is called with updateAction Nothing and at later times as updateAction (Just a) where the current value is supplied as argument.

@snoyberg
Copy link
Member

I'm not actually seeing how such a function would work. Are you missing a parameter? Is this intended to be a field in a data type?

@MaxGabriel
Copy link
Member

@nanonaren wants something like this I think:

foobar :: IO (IO Text)
foobar = mkAutoUpdate defaultUpdateSettings
  { updateAction = \maybePreviousValue -> foo -- Potentially use previous value to calculate the new value
  , updateFreq = 24 * 60 * 60 * 1000000 -- Update once per day
  }

@nanonaren It would probably help clarify things if you provided an example use case

@nanonaren
Copy link
Contributor Author

nanonaren commented Apr 22, 2016

The example by @MaxGabriel is what I'm looking for. I have a structure in memory that gets updated periodically. Specifically, it maintains a vector of computed values based on recent data in the DB. So it pulls in records after the last update time and then drops very old items. This is why I need to update the previous value rather than refresh it with a completely new one.

@snoyberg
Copy link
Member

OK, that makes sense. To provide for maximum performance and not break backwards compatibility, I'd imagine we could add a new field:

updateActionModify :: Maybe (a -> IO a)

The idea would be:

  • updateAction would always be used for the first action
  • If provided, updateActionModify would be used for subsequent actions
  • If not provided, current behavior continues

@MaxGabriel
Copy link
Member

@nanonaren Are you interested in implementing this?

@nanonaren
Copy link
Contributor Author

nanonaren commented Apr 23, 2016

Sure, I'll do it. Please check if it makes sense...

nanonaren added a commit to nanonaren/wai that referenced this issue Apr 23, 2016
@nanonaren
Copy link
Contributor Author

^ anyone want to check?

@snoyberg
Copy link
Member

snoyberg commented May 4, 2016

LGTM. I didn't review this earlier since Github doesn't send notifications for commits pinging issues/PRs.

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

3 participants