0

How would I go about mixing code/statements/functions that I want to run outside the main thread mixed in with code that strickly runs on the main thread.

In mobile world we have tools like rxjava, asynctask, runnables, rxswift and all that good stuff to just drop in lines that run in the background and not bother the fluidness of the main code.

So how to utilize asyncio lib and simply intermingle non blocking code with blocking code?

   def mumboJumboCode():
        regularStuff = doSomeRegularStuff()
        illGetItLater = sendSomeStuffToAWebsocketInTheBackground(regularStuff)
        moreRegularStuff = doSomeMoreRegularStuff()
        iDontCareWhatItReturns = sendAMessageOverTheWire(illGetItLater)
        if (moreRegularStuff => regularStuff):
              triggerALambdaSomewhereInTheCloud(moreRegularStuff)
sirvon
  • 2,547
  • 1
  • 31
  • 55

1 Answers1

0

You can always simulate blocking code while in async mode, but not the other way around.

So, if you program your system in async mode, you can set a flag in the event handler, and wait for that flag to change in a polling loop, effectively changing the mode to sync mode. If you want to something asynchronously, you can just change the behavior of the handler.

jcoppens
  • 5,306
  • 6
  • 27
  • 47
  • can you post some code or links to code that visual explain? thanks for the understanding... – sirvon Jul 11 '15 at 03:03