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

France Nouvelles Nouvelles

Using Go Defer and Rust Drop to Defer the Call to Rollback | HackerNoon
France Dernières Nouvelles,France Actualités
  • 📰 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.

Nous avons résumé cette actualité afin que vous puissiez la lire rapidement. Si l'actualité vous intéresse, vous pouvez lire le texte intégral ici. Lire la suite:

hackernoon /  🏆 532. in US

France Dernières Nouvelles, France Actualités

Similar News:Vous pouvez également lire des articles d'actualité similaires à celui-ci que nous avons collectés auprès d'autres sources d'information.

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.
Lire la suite »

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.
Lire la suite »

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.
Lire la suite »

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.
Lire la suite »

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.
Lire la suite »

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.
Lire la suite »



Render Time: 2025-04-01 03:09:11