Skip to content

Add async/await as better way to call blocking functions #1857

@CrosRoad95

Description

@CrosRoad95

Is your feature request related to a problem? Please describe.
Callbacks hell, its often hard and uncomfortable to pass all data you need to next function and some of them just can't be passed

Describe the solution you'd like
add build in mta async/await style functionality, eg.:

invokeAsync(function()
  response = fetchRemoteAsync("mtasa.com/api")
  data = fromJSONAsync(response.data)
  print(data)
  dbQueryAsync("insert into...", data)

  data = triggerClientEventAsync("getFoo", getRandomPlayer())
  print("data", data) -- prints "foo"

  while true do -- equivalent of setTimer(print, 100, 0, "hi")
    sleep(100)
    print("hi")
  end
end)

-- clientside:
addEventHandlerAsync("getFoo", root, function()
  return "foo"
end)

less code, more readable, easy to use, non blocking

Describe alternatives you've considered
/

Additional context
https://forum.mtasa.com/topic/54787-simple-sleep-function/ example how to do this

Related issues #1815

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions