-module(wait_task). -behaviour(bt_task). -export([ get_params/0, init/2, run/4 ]). -record(state, { start_timestamp, wait_time_sec }). get_params() -> ["time"]. init(#{"time" := Time_key}, BB) -> Time = blackboard:eval(Time_key, BB), %% get current timestamp and add to state #state{ start_timestamp = erlang:timestamp(), wait_time_sec = Time }. run(_Args, State = #state{start_timestamp = StartTimestamp, wait_time_sec = WaitTimeSec}, BB, _Event) -> %% if already WaitTimeSec seconds have passed, return success, otherwise running NowTimestamp = erlang:timestamp(), DiffInMicroseconds = timer:now_diff(NowTimestamp, StartTimestamp), DiffInSeconds = DiffInMicroseconds/1000000, if DiffInSeconds > WaitTimeSec -> {success, State, BB}; true -> io:format("Waiting...~n"), {running, State, BB} end.