-
Notifications
You must be signed in to change notification settings - Fork 140
Use async core interface #56
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
Conversation
|
Blocked on temporalio/sdk-core#80 |
packages/worker/native/src/lib.rs
Outdated
| /// Send an error to JS via callback using an [EventQueue] | ||
| fn send_error<T>(queue: Arc<EventQueue>, callback: Root<JsFunction>, error: T) | ||
| where | ||
| T: ::std::fmt::Display + Send + 'static, |
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.
You don't need the leading :: for these.
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.
Habit I picked up, I don't mind getting rid of it.
| }; | ||
| let queue = Arc::new(cx.queue()); | ||
|
|
||
| std::thread::spawn(move || { |
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.
Would be great to break up this big closure into smaller functions
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.
Agree, I'll do that
packages/worker/native/src/lib.rs
Outdated
| if matches!(request, Request::BreakPoller) { | ||
| break; | ||
| } else if matches!(request, Request::Shutdown) { |
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 reads a bit strange compared to just a match expression
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 think you'll like the new structure
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.
Yup, very nice. 🙌
packages/worker/native/src/lib.rs
Outdated
| // Ignore BreakPoller and Shutdown, they're handled above | ||
| Request::BreakPoller => {} | ||
| Request::Shutdown => {} |
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.
Can be Request::BreakPoller | Request::Shutdown
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.
👍
| let worker = cx.argument::<BoxedWorker>(0)?; | ||
| let queue_name = cx.argument::<JsString>(1)?.value(&mut cx); | ||
| let callback = cx.argument::<JsFunction>(2)?; |
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.
You could impl some kind of unpack function on FunctionContext that would de-dupe these preambles and make things a bit more readable
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.
You'd have to show me what you mean.
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.
@bergundy Something like this
trait FnContextExt {
fn unpack(self) -> (BoxedWorkerType, QueueNameType, CallbackType);
}
impl FnContextExt for FunctionContext {
/// Implement the three lines here and return 3-tuple (or a real struct)
}
bergundy
left a comment
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.
Thanks
packages/worker/native/src/lib.rs
Outdated
| /// Send an error to JS via callback using an [EventQueue] | ||
| fn send_error<T>(queue: Arc<EventQueue>, callback: Root<JsFunction>, error: T) | ||
| where | ||
| T: ::std::fmt::Display + Send + 'static, |
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.
Habit I picked up, I don't mind getting rid of it.
| }; | ||
| let queue = Arc::new(cx.queue()); | ||
|
|
||
| std::thread::spawn(move || { |
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.
Agree, I'll do that
packages/worker/native/src/lib.rs
Outdated
| if matches!(request, Request::BreakPoller) { | ||
| break; | ||
| } else if matches!(request, Request::Shutdown) { |
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 think you'll like the new structure
packages/worker/native/src/lib.rs
Outdated
| // Ignore BreakPoller and Shutdown, they're handled above | ||
| Request::BreakPoller => {} | ||
| Request::Shutdown => {} |
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.
👍
| let worker = cx.argument::<BoxedWorker>(0)?; | ||
| let queue_name = cx.argument::<JsString>(1)?.value(&mut cx); | ||
| let callback = cx.argument::<JsFunction>(2)?; |
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.
You'd have to show me what you mean.
Implements the Worker part of [proposal #56](https://github.com/temporalio/proposals/blob/050825aba0e2e6cde91bae81945dce082bd47622/typescript/connections.md) - Break down `Core` into `Runtime` and `NativeConnection` - Workers now require a `NativeConnection` instance instead of using the singleton `Core` connection - `Runtime` may be removed in the future but remains in the SDK to enable log forwarding from Core - By default we don't forward Core logs into node anymore This PR uses `sdk-core/master` which unblocks local activities and upsert search attributes, the last missing pieces for a feature complete SDK (apart from stack trace query).
What was changed:
Use the async core interface introduced in temporalio/sdk-core#77
Worker is now created with the static async
Worker.createmethod.How has this been tested?
Ran the existing tests which needed some modifications.
Any docs updates needed?
Docs were updated.