Page MenuHomeFeedback Tracker

Add defer operator
Closed, ResolvedPublic

Description

Is it possible to add a defer operator,
I propose to add this operator, for a delayed function / code call, which will be called after the execution of the function where it was called.

like defer in Golang

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting

Event Timeline

BIS_fnc_KK added a subscriber: BIS_fnc_KK.EditedAug 21 2022, 4:34 PM

You can do this already

[ ]spawn { _thisScript spawn { waitUntil {scriptDone _this}; systemchat "runs last” }; systemChat "runs first"};

Leopard20 added a subscriber: Leopard20.EditedAug 22 2022, 6:02 PM

You can also do this using 2 helper functions, which is more optimal than using spawn with waitUntil:

//fn_deferrer.sqf
params ["_params", "_code"];
private _deferred = [];
_params call _code;
{
  _x#0 call _x#1;
} forEach _deferred
//fn_defer.sqf
_deferred pushBack _this;
[[], {
    [[], {systemChat "runs last"}] call my_fnc_defer;
    systemChat  "runs first";
}] call my_fnc_deferrer;
dedmen closed this task as Resolved.Aug 23 2022, 2:43 PM
dedmen claimed this task.
dedmen added a subscriber: dedmen.

Won't do