문제

Once I am done in the middle of a Fiber instance fiber, i.e., I yielded from it without completing it, and I am not using fiber any more, what should I do with it? Should I explicitly destroy it, or is there something like kill for a Fiber, or will it be garbage collected properly? If it is, then how does Ruby know whether I am going to fiber.resume in the future or not?

도움이 되었습니까?

해결책

You don't have to kill it if it's already dead; yield from a fiber will do the job. You just have to make sure that the fiber instance is not stored in any variables. That's how you "free" them: the garbage collector works by periodically destroying object without any references to them. If you keep your fiber in some variable, it'll stick around in memory until you make it unreachable.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top