Using Go Defer and Rust Drop to Defer the Call to Rollback | HackerNoon

Nigeria News News

Using Go Defer and Rust Drop to Defer the Call to Rollback | HackerNoon
Nigeria Latest News,Nigeria Headlines
  • 📰 hackernoon
  • ⏱ Reading Time:
  • 46 sec. here
  • 2 min. at publisher
  • 📊 Quality Score:
  • News: 22%
  • Publisher: 51%

'Using Go Defer and Rust Drop to Defer the Call to Rollback' golang rust

My extremely slow journey to learn Rust continues, delayed by other projects. My attention in 2021 has been primarily on Go and PostgreSQL. I'm coming to appreciate and respect the database overall a lot more and wrote up some of my thoughts inOne thing that has me very interested in Rust is the tools it gives me to write code that works in exactly the way I expect it to.

func someWork error { tx, err :=db.Begin err :=foo if err !=nil { tx.Rollback return err } err=bar if err !=nil { tx.Rollback return err } return tx.Commit } func someWork error { tx, err :=db.Begin defer tx.Rollback err :=foo if err !=nil { return err } err=bar if err !=nil { return err } return tx.Commit }

func deferInLoop { for i :=0; i Drop for Transaction { fn drop { if let Some=self.transaction.take { let _=self.connection.block_on); } } } This works exactly as we'd hope -- 200 iterations and no issues. This is because each time the loop iteration ends, the transaction struct gets dropped and rollback is called, all before the next iteration begins.A transaction should end with a call to commit or rollback. If neither are called before the transaction goes out-of-scope, rollback is called. In other words, rollback is called on drop if the transaction is still in-progress.

We have summarized this news so that you can read it quickly. If you are interested in the news, you can read the full text here. Read more:

hackernoon /  🏆 532. in US

Nigeria Latest News, Nigeria Headlines

Similar News:You can also read news stories similar to this one that we have collected from other news sources.

Opinion: Pence's baby step away from Trump doesn't go far enoughOpinion: Pence's baby step away from Trump doesn't go far enoughFormer Vice President Mike Pence, who has tried to distance himself from his ex-boss Donald Trump before, is still trying to get credit for doing the bare minimum when it comes to speaking out against the former President, writes Michael D'Antonio.
Read more »

Travel to Mexico during Covid-19: What you need to know before you goTravel to Mexico during Covid-19: What you need to know before you goIf you’re planning to travel to Mexico, here’s what you’ll need to know and expect if you want to visit during the Covid-19 pandemic.
Read more »

5 Ways To Stay Calm When Things Don’t Go As Planned5 Ways To Stay Calm When Things Don’t Go As PlannedYour ability to handle the unexpected is critical to being a leader.
Read more »

Police Chief Wore ‘Let’s Go Brandon’ Sweater to Christmas PartyPolice Chief Wore ‘Let’s Go Brandon’ Sweater to Christmas PartyThe idea that a law enforcement official might wear clothing showcasing political affiliations is not exactly unprecedented. But a police chief embracing a right-wing catchphrase jokingly or otherwise struck a nerve.
Read more »

Holly Willoughby wears polka dot midi dress from go-to brand LK Bennett on This MorningHolly Willoughby wears polka dot midi dress from go-to brand LK Bennett on This MorningHolly Willoughby's latest Ghost outfit, the Alex Dress in Blue, is available in all sizes \u2013 XS to XL \u2013 on the brand's website.
Read more »

Julia Marino and Her Prada Snowboard Go Viral at the Beijing Winter OlympicsJulia Marino and Her Prada Snowboard Go Viral at the Beijing Winter OlympicsThe snowboarder had a high-fashion moment when she won Team USA’s first medal this weekend.
Read more »



Render Time: 2025-08-28 08:05:52