tractor icon indicating copy to clipboard operation
tractor copied to clipboard

Remove ``tractor.run()``

Open goodboy opened this issue 5 years ago • 0 comments

Once #181 lands and all dependent projects are ported, we can safely move to the new trio.run() based entry api.

The ideal user facing API instead looks like:

import trio
import tractor

async def main():

    # actor runtime is started implicitly inside the first used nursery if this actor is the root
    async with tractor.open_nursery() as n:
        portal = await n.run_in_actor(trio.sleep(1))
        
trio.run(main)

or, if the user wants to start up the actor runtime / tree manually:

import trio
import tractor

async def main():

    # this starts up the IPC / channel machinery without having to open an actor nursery.
    # you could also just open an actor nursery and sleep in it's body I guess?
    async with tractor.open_root_actor() as actor:
        # run a top level root actor and that's it.
        await trio.sleep_forever()
        
trio.run(main)

This is of course all up for discussion. I'm prone to maybe offer a tractor.lowlevel (like trio) for stuff like this open_root_actor().

Luckily since most of our docs reference examples, one those are changed there should be little work to do on that front.

goodboy avatar Dec 28 '20 17:12 goodboy