Module: Kernel
- Extended by:
- Polyphony::TrapInterceptor
- Includes:
- Polyphony::TrapInterceptor
- Defined in:
- lib/polyphony/core/debug.rb,
lib/polyphony/adapters/irb.rb,
lib/polyphony/extensions/kernel.rb
Overview
Kernel extensions (methods available to all objects / call sites)
Instance Method Summary collapse
-
#format_trace(args) ⇒ String
Formats a trace message.
-
#snooze ⇒ any
Switches to the next fiber in the current thread's runqueue after adding the current fiber to the runqueue.
-
#suspend ⇒ any
Switches to the next fiber in the current thread's runqueue without rescheduling the current fiber.
-
#trace(*args) ⇒ Object
Prints a trace message to
STDOUT
, bypassing the Polyphony backend.
Methods included from Polyphony::TrapInterceptor
Instance Method Details
#format_trace(args) ⇒ String
Formats a trace message.
11 12 13 14 15 16 17 18 19 |
# File 'lib/polyphony/core/debug.rb', line 11 def format_trace(args) if args.size > 1 && args.first.is_a?(String) format("%s: %p\n", args.shift, args.size == 1 ? args.first : args) elsif args.size == 1 && args.first.is_a?(String) "#{args.first}\n" else format("%p\n", args.size == 1 ? args.first : args) end end |
#snooze ⇒ any
Switches to the next fiber in the current thread's runqueue after adding the current fiber to the runqueue. This lets other fibers run, letting the current fiber eventually continue its work. This call is useful when performing long-running calculations in order to keep the program responsive.
39 40 41 |
# File 'ext/polyphony/polyphony.c', line 39 VALUE Polyphony_snooze(VALUE self) { return Backend_snooze(BACKEND()); } |
#suspend ⇒ any
Switches to the next fiber in the current thread's runqueue without rescheduling the current fiber. This is useful if the current fiber does not need to continue or will be scheduled by other means eventually.
50 51 52 53 54 55 56 |
# File 'ext/polyphony/polyphony.c', line 50 static VALUE Polyphony_suspend(VALUE self) { VALUE ret = Thread_switch_fiber(rb_thread_current()); RAISE_IF_EXCEPTION(ret); RB_GC_GUARD(ret); return ret; } |
#trace(*args) ⇒ Object
Prints a trace message to STDOUT
, bypassing the Polyphony backend.
4 5 6 |
# File 'lib/polyphony/core/debug.rb', line 4 def trace(*args) $stdout.orig_write(format_trace(args)) end |