kanit

Toy init system
Log | Files | Refs | README | LICENSE

async.md (888B)


      1 # if or if not to async
      2 
      3 Async must be used in 2 spots:
      4 * Units
      5 * Event loop
      6 
      7 Any code that is called in these spots should be marked as async.  If no code is executing concurrently, blocking may be
      8 done in an async block.
      9 
     10 An example would be in startup's initialization of the loader. `Loader::initialize` does call a blocking function
     11 (`std::fs::read`) although as no code is running concurrently, it is allowed.
     12 
     13 It is safe to use `SendWrapper` as the async executor is designated as a local executor (running in a single thread).
     14 Due to the init's job being primarily IO-bound, multithreading only introduces slowdowns with the overhead of locking.
     15 
     16 Locks should only be used where required in cases where a `RefCell` might be held over an `await` point. `Loader`
     17 contains an `ev_lock` which should be held during the event loop to ensure unit references are only held at one point.