flagsmith-nodejs-client icon indicating copy to clipboard operation
flagsmith-nodejs-client copied to clipboard

Local Evaluation without awaiting a Promise

Open cody-greene opened this issue 1 year ago • 5 comments
trafficstars

  • ~rm whitespace~
  • ~rm superfluous updateEnvironment(); this was called 2x in local evaluation mode startup. Let the polling manager make the first call.~
  • add getIdentityFlagsSync(); expects local evaluation or offline mode, and a synchronous cache. Does not return a Promise.
  • add readyCheck() Wait for the environment document to load. If the request fails then this promise is rejected. Useful for local evaluation mode.

I was rather confused that, with local evaluation mode, retrieving flags is still an async operation! Promises are entirely unnecessary in this particular situation. In fact, it forces any calling code to be async too which can be quite annoying. Once the environment document is first loaded, I should be able to check my flags in a simple synchronous fashion, while the environment updates in the background.

const flagsmith = new Flagsmith({
  enableLocalEvaluation: true
})

// need to wait for first load
await flagsmith.readyCheck()

// now evaluate with in-memory document
const flags =  flagsmith.getIdentityFlagsSync('unknown_user')
console.log(flags)

cody-greene avatar Dec 09 '23 06:12 cody-greene

Before I proceed any further with this (adding tests, better docs). Is this idea likely to be merged?

cody-greene avatar Dec 11 '23 22:12 cody-greene

Before I proceed any further with this (adding tests, better docs). Is this idea likely to be merged?

Yes, this certainly seems like a good idea to me! We would love for you to continue, and we would definitely consider merging.

matthewelwell avatar Dec 11 '23 22:12 matthewelwell

@cody-greene Are you able to work on this? If not I'll close?

dabeeeenster avatar Mar 20 '24 09:03 dabeeeenster

Yes. I'll find some time to finish this

-------- Original Message -------- On Mar 20, 2024, 2:57 AM, Ben Rometsch wrote:

@.***(https://github.com/cody-greene) Are you able to work on this? If not I'll close?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

cody-greene avatar Mar 20 '24 14:03 cody-greene

I will convert this PR to a draft in the meantime. Please feel free to change it to Ready for Review whenever it gets completed.

novakzaballa avatar Apr 24 '24 16:04 novakzaballa

@cody-greene I am closing this PR since it has not been active for a long time. Please feel free to re-open once you have a new version as per the above comments.

novakzaballa avatar May 16 '24 11:05 novakzaballa