Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:28:32+00:00 2026-06-04T13:28:32+00:00

The problem One data source generating data in format {key, value} Multiple receivers each

  • 0

The problem

  • One data source generating data in format {key, value}
  • Multiple receivers each waiting for different key

Example

Getting data is run in loop. Sometimes I will want to get next value labelled with key by using

Value = MyClass:GetNextValue(Key)

I want my code to stop there until the value is ready (making some sort of future(?) value). I’ve tried using simple coroutines, but they work only when waiting for any data.

So the question I want to ask is something like How to implement async values in lua using coroutines or similar concept (without threads)?

Side notes

The main processing function will, apart from returning values to waiting consumers, process some of incoming data (say, labeled with special key) itself.

The full usage context should look something like:

-- in loop
    ReceiveData()
    ProcessSpecialData()
--

-- Called outside the loop:
V = RequestDataWithGivenKey(Key)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:28:33+00:00Added an answer on June 4, 2026 at 1:28 pm

    How to implement async values

    You start by not implementing async values. You implement async functions: you don’t get the value back until has been retrieved.

    First, your code must be in a Lua coroutine. I’ll assume you understand the care and feeding of coroutines. I’ll focus on how to implement RequestDataWithGivenKey:

    function RequestDataWithGivenKey(key)
      local request = FunctionThatStartsAsyncGetting(key)
      if(not request:IsComplete()) then
        coroutine.yield()
      end
    
      --Request is complete. Return the value.
      return request:GetReturnedValue()
    end
    

    FunctionThatStartsAsyncGetting returns a request back to the function. The request is an object that stores all of the data needs to process the specific request. It represents asking for the value. This should be a C-function that starts the actual async getting.

    The request will be either a userdata or an encapsulated Lua table that stores enough information to communicate with the C-code that’s doing the async fetching. IsComplete uses the internal request data to see if that request has completed. GetReturnedValue can only be called when IsComplete returns true; it puts the value on the Lua stack, so that this function can return it.

    Your external code simply needs to handle the async stuff internally. Between resumes of these Lua coroutines, you’ll need to pump whatever async stuff is doing the fetching, if there are outstanding requests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
My problem seems to be this: heap data allocated by one thread (that later
I have a problem with my WCF Data Service, and this one is just
I am encountering a funny problem with UIPickerView. My data source has 2 items:
If one wants to paginate results from a data source that supports pagination we
I've got a problem with getting a ComboBox to operate as expected when data
Problem One friend suggested an interesting problem. Given the following code: public class OuterClass
This is a problem one of our developers brought to me. He stumbled across
My problem is one that you would think is quite common, but I haven't
I got one problem at my exam for subject Principal of Programming Language. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.