You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Write a tutorial about "Build an Autocomplete with Structured Concurrency using Effection in React" #880
The autocomplete example's logic is ready. We should now write a blog post about it. The focus should be on describing the pattern of doing autocomplete with SC. The main takeaway is that SC organizes operations into a tree where an operation can have children. One of the rules of SC is that a child can not outlive its parent, we can use this rule to design out autocomplete. We'll build from nothing to a working autocomplete in React.
changed the title [-]Write tutorial about "Build an Autocomplete with Structured Concurrency using Effection in React"[/-][+]Write blog post about "Build an Autocomplete with Structured Concurrency using Effection in React"[/+]on Jan 6, 2024
changed the title [-]Write blog post about "Build an Autocomplete with Structured Concurrency using Effection in React"[/-][+]Write a tutorial about "Build an Autocomplete with Structured Concurrency using Effection in React"[/+]on Jan 6, 2024
I think we'll start with a more introductory blog post first - Retrying in Javascript with Structured Concurrency using Effection.
We can begin the blog post with an example of 2 retries of a fetch call written in node and from there we can sprinkle in two more requirements involving a timer and the retry limit changing based on the response status code? The additional requirements will make it clear that it would be a pain in the butt to implement correctly and we'll say it's easy with effection and show how it's done.
Are the examples below how an average developer would write these implementations in javascript?
I don't think so. It would look close to that in Effection because we can easily interrupt any operation; without Effection, there would be no way to stop this code. Even if we use an abort controller, it would run while loop. Maybe if you checked the state of the abort controller on every cycle.
retry-fetch is perhaps the closest to what we're trying to show here. Here is the main code from this library.
returnnewPromise(function(resolve,reject){varwrappedFetch=function(attempt){// As of node 18, this is no longer needed since node comes with native support for fetch:/* istanbul ignore next */var_input=typeofRequest!=='undefined'&&inputinstanceofRequest
? input.clone()
: input;fetch(_input,init).then(function(response){if(Array.isArray(retryOn)&&retryOn.indexOf(response.status)===-1){resolve(response);}elseif(typeofretryOn==='function'){try{// eslint-disable-next-line no-undefreturnPromise.resolve(retryOn(attempt,null,response)).then(function(retryOnResponse){if(retryOnResponse){retry(attempt,null,response);}else{resolve(response);}}).catch(reject);}catch(error){reject(error);}}else{if(attempt<retries){retry(attempt,null,response);}else{resolve(response);}}}).catch(function(error){if(typeofretryOn==='function'){try{// eslint-disable-next-line no-undefPromise.resolve(retryOn(attempt,error,null)).then(function(retryOnResponse){if(retryOnResponse){retry(attempt,error,null);}else{reject(error);}}).catch(function(error){reject(error);});}catch(error){reject(error);}}elseif(attempt<retries){retry(attempt,error,null);}else{reject(error);}});};
This is probably the best example of how someone would do this without Effection, Observables or Effect.ts.
@taras - not sure if @ notifications get sent if it's added in an edit 🤷
there would be no way to stop this code. Even if we use an abort controller, it would run while loop. Maybe if you checked the state of the abort controller on every cycle.
Are we talking about just dropping/stopping everything at any point in the code? Isn't the abort controller (in my last example) saying, after 5 seconds, we're going to stop fetching and let it run the rest of the while loop but it won't do another cycle?
retry-fetch is perhaps the closest to what we're trying to show here. Here is the main code from this library.
So then would the structure of the blogpost be:
Here's a quick (but full of compromises) way of doing it (my examples)
But here's a better way of doing it (with retry-fetch) because the examples from [1] is missing {x}
saying, after 5 seconds, we will stop fetching and let it run the rest of the while loop, but it won't do another cycle?
It's worth a try. The libraries I listed above don't seem to support AbortController explicitly. fetch-retry tests don't have a mention of abort. What do you think about making a small test harness to test the behavior of these different libraries? We can figure out the narrative once we have a better understanding of what the status quo is.
@minkimcello I found an interesting library called abort-controller-x for composing abort controller aware asyncronous functions. Interestingly, they wrote the code the same way you did in your example. The point of this library is that it makes it easy to thread the abort controller through many async operations. We could mention it in our "Need to thread abort controllers to each layer or use something like abort-controller-x to compose abort controller aware async operations"
I just want to make sure that we don't drown out the simplicity of the Effection example by showing too many ways to do it.
We'll just jump right into the Effection implementation and highlight all the advantages without referencing other libraries. That should simplify the blogpost quite a bit.
Activity
[-]Write tutorial about "Build an Autocomplete with Structured Concurrency using Effection in React"[/-][+]Write blog post about "Build an Autocomplete with Structured Concurrency using Effection in React"[/+][-]Write blog post about "Build an Autocomplete with Structured Concurrency using Effection in React"[/-][+]Write a tutorial about "Build an Autocomplete with Structured Concurrency using Effection in React"[/+]minkimcello commentedon Jan 31, 2024
I think we'll start with a more introductory blog post first -
Retrying in Javascript with Structured Concurrency using Effection.We can begin the blog post with an example of 2 retries of a fetch call written in node and from there we can sprinkle in two more requirements involving a timer and the retry limit changing based on the response status code? The additional requirements will make it clear that it would be a pain in the butt to implement correctly and we'll say it's easy with effection and show how it's done.
taras commentedon Jan 31, 2024
Sounds good. Let's do it!
minkimcello commentedon Feb 1, 2024
@cowboyd I wrote the javascript examples of fetching with additional requirements (without effection)
Simple Retries
More Requirements
Retry twice but up to 5 times for 5xx error codes
Retry twice but up to 5 times for 5xx error codes, cancel after 5 seconds
taras commentedon Feb 2, 2024
I don't think so. It would look close to that in Effection because we can easily interrupt any operation; without Effection, there would be no way to stop this code. Even if we use an abort controller, it would run while loop. Maybe if you checked the state of the abort controller on every cycle.
Let me do some research.
taras commentedon Feb 2, 2024
retry-fetchis perhaps the closest to what we're trying to show here. Here is the main code from this library.This is probably the best example of how someone would do this without Effection, Observables or Effect.ts.
minkimcello commentedon Feb 2, 2024
@taras - not sure if @ notifications get sent if it's added in an edit 🤷
Are we talking about just dropping/stopping everything at any point in the code? Isn't the abort controller (in my last example) saying, after 5 seconds, we're going to stop fetching and let it run the rest of the while loop but it won't do another cycle?
So then would the structure of the blogpost be:
retry-fetch) because the examples from [1] is missing {x}taras commentedon Feb 2, 2024
It's worth a try. The libraries I listed above don't seem to support AbortController explicitly. fetch-retry tests don't have a mention of abort. What do you think about making a small test harness to test the behavior of these different libraries? We can figure out the narrative once we have a better understanding of what the status quo is.
minkimcello commentedon Feb 3, 2024
Updated outline
minkimcello commentedon Feb 5, 2024
@taras ☝️
taras commentedon Feb 5, 2024
Yeah, that looks good. I'm going to put together a small test to see how it behaves
taras commentedon Feb 6, 2024
@minkimcello I found an interesting library called abort-controller-x for composing abort controller aware asyncronous functions. Interestingly, they wrote the code the same way you did in your example. The point of this library is that it makes it easy to thread the abort controller through many async operations. We could mention it in our "Need to thread abort controllers to each layer or use something like abort-controller-x to compose abort controller aware async operations"
https://github.com/deeplay-io/abort-controller-x/blob/master/src/retry.ts#L44-L93
This is the best example of writing a retry/backoff using an abort controller.
It looks almost identical to how you'd implement it in Effection except you don't need to manage abort controller manually.
cowboyd commentedon Feb 6, 2024
I just want to make sure that we don't drown out the simplicity of the Effection example by showing too many ways to do it.
minkimcello commentedon Feb 7, 2024
We'll just jump right into the Effection implementation and highlight all the advantages without referencing other libraries. That should simplify the blogpost quite a bit.
minkimcello commentedon Feb 7, 2024
@taras @cowboyd How does this look? https://github.com/minkimcello/effection-retries/blob/main/blog.ts - this will be for the code snippet for the blog post.
There's also this file that I was running locally https://github.com/minkimcello/effection-retries/blob/main/index.ts to run a fake fetch.
I noticed I couldn't resolve from inside the while loop. Is that by design?
taras commentedon Feb 7, 2024
@minkimcello I think we can make that example much simpler.
runhere instead ofmainminkimcello commentedon Feb 9, 2024
@taras I was trying to replace the fetch with a fake fetch and test out the script. but I noticed none of the console logs from operations inside
race()aren't being printed. are we calling the operations incorrectly inside race? https://github.com/minkimcello/effection-retries/blob/main/index.ts#L60-L64cowboyd commentedon Feb 10, 2024
That is very odd. I would expect it to log... unless there was an error or someone else won the race.
taras commentedon Feb 10, 2024
We figured it out. It's a missing yield in front of race
minkimcello commentedon Feb 13, 2024
wrote the code examples (and not much of the text (yet)) for the blogpost: thefrontside/frontside.com#374
Is that too long? Maybe we can cut out the last part? the
Reusablesection