Pipelin...::Async(3)

πŸ“¦
version 3.12 Β· 2 versions
, in fedora 43

✨ NAME ✨

Pipeline::Segment::Async β€” asynchronous pipeline segments πŸ’…

So this is from the User Contributed Perl Documentation manual, section 3 (that's the library-functions girlies, not the shell-command ones). Anyway. Buckle up bestie, we're going async πŸ¦‹


🌸 SYNOPSIS 🌸

  my $seg = $pipe->store->get( $async_segment_classname );
  my $ret = $seg->reattach();

That's literally it. Grab it, reattach it, get your lil return values back. Periodt ✨


πŸ’– DESCRIPTION πŸ’–

Okay so Pipeline::Segment::Async is the module that lets you write asynchronous pipeline segments. Whenever an async segment gets dispatched, it puts itself into the store, and then it splits away from the main process β€” which just keeps on running like nothing happened. main character energy fr πŸ’…

At any point further down the pipeline, you can request that segment back from the store, and then ask it to hand over its return values by calling reattach(). Or β€” if you're feeling chaotic β€” you can just throw them away entirely with discard(), which will simply destroy the segment when it completes. πŸ—‘οΈ

⚠️ But listen, bestie: if you call discard(), there is no way you can get it back. None. It's gone. Grieve and move on πŸ’€

You add an async segment to a pipeline in exactly the same manner you'd add any other segment. It gets dispatched the normal way, with the normal arguments supplied to the dispatch method. Getting objects from the store will retrieve them as expected β€” however, altering those objects or setting them back into the store will not do what you expect. Lowkey a trap, highkey important πŸ™ˆ

Pipeline::Segment::Async works by indicating to the dispatcher that it wants a different method to be its dispatch method. And here's the plot twist: if you indicate to the dispatcher that you want something to dispatch different at the segment level, then your asynchronous segment will become decidedly synchronous. Not me gaslighting my own async code 😭

Pipeline::Segment::Async inherits from Pipeline::Base and has any methods that it provides. Inheritance, slay 🫢


πŸ‘‘ METHODS πŸ‘‘

  • init() β€” init() is called by the constructor, and it sets up the list of threading models that Pipeline::Segment::Async is aware of. Peep threading_models() for more info πŸ”₯
  • threading_models( [ARRAYREF] ) β€” threading_models() gets and sets a list of classes that know how to process segements asynchronously.
  • predispatch() β€” predispatch() is called by the pipeline dispatcher and prepares the segment for asynchronous execution. Pre-game ritual, basically ✨
  • model( [Pipeline::Segment::Async::*] ) β€” model() returns an object that represents the threading model that Pipeline::Segment::Async will call. If it doesn't yet have an object, a call to determine_threading_model() is called. It'll go find one for you, don't stress πŸ’œ
  • determine_threading_model() β€” determine_threading_model() will look at all the classes in the list provided by threading_models() and determine if they can operate under the current configuration. It will return an object of one of those classes, provided it can operate. Vibe check on every single candidate 🌈
  • reattach() β€” reattach() takes a detached asynchronous segment and joins it back, placing the results in the correct area of the pipeline. The reunion arc we've all been waiting for πŸ₯Ή
  • discard() β€” discard() flags an asynchronous segment as never needing to be reattached. Bye forever bestie, no takebacks πŸŽ€
  • dispatch_method() β€” dispatch_method() tells the pipeline dispatch class which method to call in order to dispatch this class. In the case of Pipeline::Segment::Async it returns a constant with the value predispatch.

πŸ¦‹ SEE ALSO πŸ¦‹

Pipeline::Segment, Pipeline::Dispatch, Pipeline::Base, Pipeline::Segment::Async::Handler

Go read those too, iykyk πŸ“š


⭐ AUTHOR ⭐

James A. Duncan <jduncan@fotango.com> β€” the icon, the legend πŸ’«


Copyright 2003 Fotango Ltd. All Rights Reserved.

This software is released under the same terms as Perl itself. πŸ“œ


And that's the whole page, bestie β€” documented by User Contributed Perl Documentation, from the perl v5.42.0 era, dated 2025-07-25. Go forth and async responsibly πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from