avatarTrevor-Indrek Lasn

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2482

Abstract

But I learned to forgive. I learned to practise empathy and understand the 7-year-old, I knew she hadn’t intended to hurt Betsy. We never told her that Besty died but I am sure she would have been mortified and filled with remorse for a long time. That idea of empathy, the understanding that people have different values, priorities or ethics and behave in different ways has always helped me to forgive. I did not believe in carrying grudges, life was too short to be resentful.</p><p id="b8f5" type="7">That same idea of empathy and forgiveness was also the reason I stayed in abusive relationships</p><h2 id="1ccb">Abusers use forgiveness against you</h2><p id="ff7a"><i>“You are not being fair, people make mistakes!” “Come on, that was ages ago, have you still not forgiven me?” “I said I was sorry, what more do you want?”</i></p><p id="3167">These are some of the things my ex would say when I got upset about his behaviour. When you are in an abusive relationship, the concept of forgiveness can quickly become a weapon the abuser uses to keep you trapped. The idea that you must forgive them is like permission to continue with the abuse. Lundy Bancroft, who has worked with over 2000 abusive men writes:</p><p id="7386" type="7">“My clients demand forgiveness while continuing to insult, threaten, demand immediate responses, attend only to their own needs, and more.” (Why Does He Do That? p. 217)</p><h2 id="f5de">Forgiveness requires remorse</h2><p id="9234">I always thought forgiveness was unconditional. Although I am not religious, I was brought up going to church and reading the bible. The concept of forgiveness I had was influenced by the phrases and sermons I had picked up at a young age. <i>“Bear with each other and <b>forgive</b> one another if any of you has a grievance against someone. <b>Forgive</b> as the Lord forgave you.” </i>I thought it meant that you have to forgive everyone and anyone no matter what they had done. But there is one point I never knew: This idea of forgiveness is based on the assumption that the person I am forgiving shows remorse.</p><p id="c92b" type="7">Overlooked in common Christian understanding of forgiveness is the necessary part of repentance by the wrongdoer. John McKinley</p><p id="d22c">One of the most difficult concepts to understand after <a href="https://readmedium.com/13-signs-i-dated-a-narcissist-44d1db6ee3e4">my relationship with a narcissist</a> was that there are people who are incapable of feelin

Options

g remorse. He never apologised or cared about what happened to me. When he left, it was as if he had turned off a switch, his new victim was all that mattered and I never existed. Part of me was hoping for a long time that I would receive an apology. But I know that it will not happen. Although I understand now <a href="https://readmedium.com/how-a-narcissist-prepares-you-for-the-abuse-6383e7c92873">how abusive he was</a>, in his mind, he has done nothing wrong. <i>He does not seek forgiveness.</i></p><h2 id="5d37">Forgive yourself</h2><p id="46a4">I don’t think I need to forgive him to lead a happier and healthier life. I do not believe that forgiveness is part of the healing process unless it is directed at myself. <i>Forgiving yourself is key</i>.</p><p id="7171">Forgive yourself for not seeing it, for staying longer than you should have. Forgive yourself for moments you were weak and for moments when you might feel week again. Forgive yourself for ways you have behaved or things you have said. Forgive yourself for all the things you feel remorse over. Forgive yourself for never being able to forgive those that show no remorse.</p><h2 id="2210">More from Kara Summers:</h2><div id="b84b" class="link-block"> <a href="https://readmedium.com/do-you-feel-like-you-are-constantly-upsetting-your-partner-b1e9f5fcd6df"> <div> <div> <h2>Do You Feel Like You Are Constantly Upsetting Your Partner?</h2> <div><h3>Make sure you aren’t the one who is the real victim.</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*7hsqJBnmFY3IjI7k)"></div> </div> </div> </a> </div><div id="fc43" class="link-block"> <a href="https://readmedium.com/a-day-in-the-life-of-a-toxic-relationship-ffb487a213ec"> <div> <div> <h2>A Day in the Life of a Toxic Relationship</h2> <div><h3>Many don’t recognise narcissistic abuse when they are caught in the middle.</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*ul7zBaj8k26PDM4k)"></div> </div> </div> </a> </div></article></body>

How to Improve Your Asynchronous JavaScript Code With Async and Await

Photo by Max Nelson on Unsplash

If you’ve had the chance to observe modern JavaScript code, there are high chances that you’ve seen the async and await syntax somewhere.

Async/await is arguably one of the best-received new additions to the language. Async/await makes the asynchronous code appear and behave like synchronous code. Async/await are promise-based.

Before we jump into async/await, we must understand what promises are and the role they play.

Promises

A Promise is an object representing the eventual completion or failure of an asynchronous operation.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises

Why do we need the asynchronous code, anyway?

JavaScript is a single-threaded language — which means JavaScript can only do one thing at once. Imagine calling our API synchronously and blocking the entire thread for the API call duration — our users would have to wait 30 seconds or as long it takes for the network request to resolve — a big no-no!

In case you’re interested to learn more — here’s a more in-depth explanation about asynchronous programming with JavaScript.

The way we used to handle asynchronous JavaScript code was via callbacks. Chances are high that you’ve come across callbacks.

What are callbacks?

A callback function, also known as a higher-order function, is a function that is passed to another function. Functions are first class citizens in JavaScript — this means they can be passed as arguments to functions.

You might have seen jQuery specific code like this.

The following code attaches an event listener on our button and calls the alert once it’s triggered.

Where is the callback? Can you tell?

You probably can — it’s the anonymous function inside the click function parentheses.

https://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/

Callbacks in a nutshell: we trigger a function, do some stuff, and then call another function.

Callbacks are not all bad; they worked — they still do. But, what happens if we have a callback inside a callback, inside a callback — you get the point. It gets really messy and unmaintainable really quick.

The problem described above is named “callback hell.”

http://callbackhell.com/

Here’s one more example to seal the case for callbacks.

We have a melon!

We check if we have a melon inside the array — if we do, we chew the melon. After chewing, we throw away the melon. We’re also handling exceptions with the err callback.

Hey — we have a banana instead!

Note: the err callback is always the first argument in the Node world — best practices!

Just to throw you off a little — I made the previous code as readable as I can. Here’s how it might look more often:

mini callback hell; technically, having anonymous arrow functions would be the remedy but still is not the perfect solution.

You can imagine, a couple more callbacks and we’re on the highway to [callback] hell — pun intended!

Promises to the Rescue!

Promises are a clean way to write asynchronous code. The promise has a single argument, which is a callback.

The callback has two arguments, the reject and resolve conditions.

And if we use the arrow function to shorten the code:

Inside the promise block, we can decide when to resolve and when to reject the promise.

Inside the promise we check if we have a melon. If we do, let’s resolve the function with the value we pass inside resolve — we can pass literally any value to the resolve.

Promises are immediately invoked/resolved, thus why we see the console.log without calling the promise.

Promises are called and chained with the then and catch methods. Think of it like this: the promise has resolved with a value — what do we do with it?

This is where the then and catch syntax comes in. They are both callbacks which accept one argument, which is the return value passed inside the promise.

Here’s how we could handle a promise rejection:

Handling a promise rejection with catch()

Right, now our promise is not very dynamic — why?

Well, because we have an if statement that isn’t dynamic. Promises are extremely powerful when wrapped inside a function. We call them higher order functions.

Wrapping our promise inside a function

Do you notice the small change? We wrapped our promise inside a function which takes one argument in this case. This gives our promises huge flexibility. We can pass any condition to our promise and based on that condition, it will get either rejected or resolved.

Here’s the fully working promise which gets resolved.

Resolved promise

And the rejected promise.

Rejected promise

Starts to look familiar? You might have seen Axios API calls like the one below.

Or the fetch API call;

What do they have in common?

Well, for starters they’re both a promise. They’re fundamentally using promises under the “hood”. Just like we wrapped our promise inside a function, so do both of these examples.

Secondly, they’re both asynchronous code. Promises are naturally asynchronous.

Here’s how an asynchronous API call looks like:

It’s safe to say promises are much better than callbacks. Promises have their own flaws although — promises can get out of hand quite quickly.

What if there’s a better way, an even cleaner way. Async/await to the rescue!

https://codesandbox.io/s/p9mr3jzwp0?autoresize=1&expanddevtools=1&hidenavigation=1

We mark the function as async — inside the function we mark the asynchronous code with await . JavaScript will resolve the promise and then move on to the next line. In a nutshell, we change the asynchronous code to read like synchronous code while still running asynchronously.

Notice how we don’t call the promise constructor anymore and how there are much less then() and catch() methods.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

What About Error Handling?

Our current async/await doesn’t handle exceptions. This can lead to catastrophic bugs which might crash your app.

Try…catch to the rescue!

Wrapping our async function inside try catch block

The try catch block attempts to execute the code and if it runs into any exceptions/problems, it passes the error object to the catch block and executes the code inside the catch block.

Here’s how our async/await fetch would look with error handling.

This is just one of many examples, there are many ways to leverage async/await. If you’re curious — here’s a pretty good example StackOverflow answer exploring the alternatives.

If you really want to know how to manage promises and how asynchronous JavaScript code works, I recommend reading through the “JavaScript with Promises: Managing Asynchronous Code” book.

Thanks for reading and I hope you found this useful! ❤

JavaScript
Programming
Technology
Web Development
Promises
Recommended from ReadMedium