ELSEIF
Your brief EB
475 stories from 211 feeds 1250 clusters Refreshed 1 minute ago next pull 00:10

LANGUAGES Signal 124

Using a Ruby Fiber to convert block-scoped APIs into start and stop methods

Illustration only Photo by Mika Baumeister on Unsplash

A developer demonstrates using a Ruby Fiber to invert a block-scoped library API into distinct start and stop methods, avoiding the overhead of threads and queues.

WHY IT MATTERS

This pattern solves lifecycle mismatches where a framework like RSpec provides setup and teardown hooks but no around hook. It offers a lightweight, blocking alternative to threads for smuggling resources out of blocks.

Written by elseif from the cluster below · every claim links back to a source

The three things worth knowing

01

A Fiber can convert a block-scoped API into start and stop methods by yielding the resource on the first resume and finishing the block on the second.

02

This avoids the overhead and complexity of using a Thread with two Queues to manage execution flow.

03

The pattern addresses framework mismatches, such as RSpec lacking an around(:suite) hook for block-scoped libraries.

THE CLUSTER

Same story, 1 feed.

ORDERED BY FIRST SEEN
island94.org via Lobsters Converting a Ruby block interface to start/stop methods with a Fiber Open ↗