-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for async functions #313
base: main
Are you sure you want to change the base?
Conversation
Tests are hanging because |
|
||
while (!initialized) // Wait for startup | ||
{ | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there's a better pattern for doing this, also we should maybe add a 50ms sleep here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps TaskCompletionSource<T>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also use some event (for example, ManualResetEventSlim
or AutoResetEvent
) instead of a loop in the above initialization thread.
// Clean-up interns | ||
NewEventLoopFactory?.Dispose(); | ||
AsyncioModule?.Dispose(); | ||
// TODO: Add more cleanup code here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO is to clean up the currently static globals which we never dispose of, but are cleaned up automatically. We should dispose of them incase people recycle environments.
|
||
public EventLoop() | ||
{ | ||
loop = NewEventLoopFactory!.Call(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call can return a null
? If so, why not simply throw here if null
?
close?.Call(); | ||
} | ||
|
||
public void Dispose() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should ensure that Dispose()
can be called multiple times. Not sure if this implementation handles that.
IsDisposed = true; | ||
} | ||
|
||
public PyObject RunTaskUntilComplete(PyObject coroutine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public APIs on a type that implement IDisposable
typically throw an ObjectDisposedException
when they are disposed.
|
||
while (!initialized) // Wait for startup | ||
{ | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps TaskCompletionSource<T>
?
|
||
while (!initialized) // Wait for startup | ||
{ | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also use some event (for example, ManualResetEventSlim
or AutoResetEvent
) instead of a loop in the above initialization thread.
Hi @tonybaloney et. al, |
Concept:
Coroutine[T_Yield, T_Send, T_Return]
will be mapped to anICoroutine<Tyield, TSend, TReturn>
, similar to GeneratorAsTask()
which returns aTask<TYield>
by executing the following:The code generator has been updated to reflect the function to
Task<TYield>
as moves theAsTask()
execution outside of the initial GIL block to ensure they don't get deadlocked.