1 /** 2 This module implements the ScriptFiber class, used internally by VirtualMachine 3 to schedule asynchronous calls to ScriptFunctions. 4 5 ──────────────────────────────────────────────────────────────────────────────── 6 7 Copyright (C) 2021 pillager86.rf.gd 8 9 This program is free software: you can redistribute it and/or modify it under 10 the terms of the GNU General Public License as published by the Free Software 11 Foundation, either version 3 of the License, or (at your option) any later 12 version. 13 14 This program is distributed in the hope that it will be useful, but WITHOUT ANY 15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 16 PARTICULAR PURPOSE. See the GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 module mildew.vm.fiber; 22 23 import core.thread.fiber; 24 25 import mildew.types; 26 import mildew.vm.virtualmachine; 27 28 /** 29 * This is ultimately the return value of setTimeout and the like 30 */ 31 class ScriptFiber : Fiber 32 { 33 /// Constructor 34 package this(string name, VirtualMachine vm, ScriptFunction func, ScriptAny thisToUse, ScriptAny[] args) 35 { 36 _name = name; 37 super({ 38 this._result = vm.runFunction(func, thisToUse, args); 39 }); 40 } 41 42 /// result property 43 ScriptAny result() { return _result; } 44 45 /// This is the whole point of this class: to avoid seeing core.thread.fiber.Fiber 46 override string toString() const 47 { 48 return _name; 49 } 50 51 private: 52 string _name; 53 ScriptAny _result; 54 }