I'm doing some basic work with effect right now, just making an API client and having effect piped methods as the core of it.
I'm not sure if my design of the system is incorrect when it comes to what effect wants to see, but I have some common setup and common ways to handle running each request so I extracted it into its own sub effect. The only issue with this approach is now when I have other Effects outside part of my pipeline is calling
Effect.runPromise(SharedLogic())
Effect.runPromise(SharedLogic())
. I feel like I'm missing something here, but perhaps its fine to call Effect.runPromise inside of an Effect.runPromise. For reference here's what a basic usage might look like:
controller:
// What I want to expose to devs to use. Effect.runPromise(CreateUserIntegration(user_creds));
// What I want to expose to devs to use. Effect.runPromise(CreateUserIntegration(user_creds));
methods:
export const CreateUserIntegration = (user_creds) => { GetUrl(user_creds).pipe( Effect.tryMapPromise({ try: async (url) => { // save db creds & return url for more use db.save() return url }, catch: (err) => err; }), Effect.tryMapPromise({ try: async (url) => { return Effect.runPromise( // Shared Logic that just handles fetching AuthenticatedMethodCall(user_creds, "endpoint to hit") ) }, catch: (err) => err; }) )};
export const CreateUserIntegration = (user_creds) => { GetUrl(user_creds).pipe( Effect.tryMapPromise({ try: async (url) => { // save db creds & return url for more use db.save() return url }, catch: (err) => err; }), Effect.tryMapPromise({ try: async (url) => { return Effect.runPromise( // Shared Logic that just handles fetching AuthenticatedMethodCall(user_creds, "endpoint to hit") ) }, catch: (err) => err; }) )};
So my code works as shown and I get the results I want, it just feels wrong to call an Effect.runPromise() inside an Effect.runPromise(). Am I doing something wrong or is this a reasonable approach?