Giter Site home page Giter Site logo

Use shorter lifetimes about async_nursery HOT 3 CLOSED

najamelan avatar najamelan commented on June 8, 2024
Use shorter lifetimes

from async_nursery.

Comments (3)

najamelan avatar najamelan commented on June 8, 2024 1

You can't spawn non static futures on any executor without unsafe. The problem is that you can use std::mem::forget to leak the nursery, which would then outlive it's parent scope, which might hold the pointed to value. Thus when the stack frame ends, that value get's dropped, but the nursery can outlive it and still run code that has a reference to that memory. That is a memory safety issue which is not allowed in safe rust.

The only crate that can help you here is https://docs.rs/async-scoped which requires you use unsafe. If you want to go that path, I would suggest you use async-scoped. Unless there is some very good arguments for it and it can be implemented cleanly, I don't have any plans to add such an unsafe API to async_nursery. That being said, if you have some very compelling argument, please share.

Some more discussion about the issue can be found here: tokio-rs/tokio#1879 (comment)

from async_nursery.

najamelan avatar najamelan commented on June 8, 2024

ps: I'm adding this to the readme: 6c2620e#diff-04c6e90faac2675aa89e2176d2eec7d8R69

ps2: If you are struggling to design something, don't hesitate to ask. Maybe there's a better way to achieve what you want.

from async_nursery.

alexkreidler avatar alexkreidler commented on June 8, 2024

Thanks!

from async_nursery.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.