Skip to content

Commit

Permalink
smol hacks fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Aug 3, 2024
1 parent f1023d8 commit cb2138c
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/hacks.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,35 @@ class Fiber
if handler = Hacks.fiber_on_unhandled_exception
handler.call ex
else
io = {% if flag?(:preview_mt) %}
IO::Memory.new(4096) # PIPE_BUF
{% else %}
STDERR
{% end %}
if name = @name
STDERR.print "Unhandled exception in spawn (name: #{name}): "
io << "Unhandled exception in spawn(name: " << name << "): "
else
STDERR.print "Unhandled exception in spawn: "
io << "Unhandled exception in spawn: "
end
ex.inspect_with_backtrace(STDERR)
ex.inspect_with_backtrace(io)
{% if flag?(:preview_mt) %}
STDERR.write(io.to_slice)
{% end %}
STDERR.flush
end
ensure
# Remove the current fiber from the linked list
Fiber.inactive(self)
Fiber.inactive(self)

# Delete the resume event if it was used by `yield` or `sleep`
@resume_event.try &.free
@timeout_event.try &.free
@timeout_select_action = nil
# Delete the resume event if it was used by `yield` or `sleep`
@resume_event.try &.free
@timeout_event.try &.free
@timeout_select_action = nil

@alive = false
{% unless flag?(:interpreted) %}
Crystal::Scheduler.stack_pool.release(@stack)
{% end %}
Crystal::Scheduler.reschedule
@alive = false
{% unless flag?(:interpreted) %}
Crystal::Scheduler.stack_pool.release(@stack)
{% end %}
Fiber.suspend
end
end

0 comments on commit cb2138c

Please sign in to comment.