Giter Club home page Giter Club logo

Comments (7)

IMax153 avatar IMax153 commented on August 28, 2024

Closing as completed by #445

from io.

evelant avatar evelant commented on August 28, 2024

@IMax153 Why does the signature for getOption include Error? Since it will never hit the resolver function shouldn't it be Effect<never, never, Option.Option<Value>> instead?

 /**
     * Retrieves the value associated with the specified key if it exists.
     * Otherwise returns `Option.none`.
     */
    getOption(key: Key): Effect.Effect<never, Error, Option.Option<Value>>;

from io.

IMax153 avatar IMax153 commented on August 28, 2024

cc @tim-smart

from io.

tim-smart avatar tim-smart commented on August 28, 2024

The error is there because a cache entry can still be in a pending state, in the case where the lookup effect is async.

If the cache entry is in a pending state, then it will await the underlying Deferred and pass any errors back to the caller.

from io.

evelant avatar evelant commented on August 28, 2024

@tim-smart OK makes sense. Perhaps there's a need for another function then. A sort of getImmediateOption that will run sync without any Error only returning the entry if it's actually already cached, ignoring any pending.

I think that may be the more useful behavior. The current getOption is basically just a shorthand for the following.

pipe(
   someCache.contains(key),
   T.ifEffect(
     pipe(cache.get(key), T.map(O.some)), 
     T.succeedNone()
   )

AFAIK there's no way to do a getImmediateOption with the current Cache api. I think it would be useful for situations where you want to take different actions based on whether a value is immediately available because a pending cache request could take an arbitrary amount of time to complete.

from io.

tim-smart avatar tim-smart commented on August 28, 2024

Yes I don't see an issue with another API for getting a completed cache value.

readonly getOptionComplete: (key: Key) => Effect<never, never, Option<Value>>

from io.

IMax153 avatar IMax153 commented on August 28, 2024

Closing as completed by #448

from io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.