Refactor fiber creation from a static `Fiber.create` method to a constructor-based `new Fiber` pattern. This introduces a `fiber_instantiate` native that returns the Fiber class itself, allowing `new Fiber` to invoke `fiber_new` for validation and creation. A shared `validateFn` helper is added to centralize function argument checking, replacing inline validation in both `fiber_new` and `fn_new`. All test files are updated to use the new syntax, and the old `create_wrong_arg_type` test is replaced with `new_wrong_arg_type`.
20 lines
290 B
Plaintext
20 lines
290 B
Plaintext
var b = new Fiber {
|
|
IO.print("fiber b")
|
|
}
|
|
|
|
var a = new Fiber {
|
|
IO.print("begin fiber a")
|
|
b.run
|
|
IO.print("end fiber a")
|
|
}
|
|
|
|
IO.print("begin main")
|
|
a.run
|
|
IO.print("end main")
|
|
|
|
// expect: begin main
|
|
// expect: begin fiber a
|
|
// expect: fiber b
|
|
// expect: end fiber a
|
|
// expect: end main
|