DenoDDeno
Powered by
NickN
Denoβ€’3y agoβ€’
3 replies
Nick

Return lazy struct fields from Op

My goal is to build a plugin system which allows invoking user defined code. One of the features I am looking to support is the ability to invoke user provided functions with function parameters, an example:
// Ideally, I can model this in an Op:
type Input = {
  lazyValueA: () => Promise<number>;
  lazyValueB: () => Promise<number>;
}

// Example usage
const userCallback: (input: Input) => Promise<number> = async ({lazyValueA, lazyValueB}) => {
  return (await lazyValueA()) + (await lazyValueB());
}
// Ideally, I can model this in an Op:
type Input = {
  lazyValueA: () => Promise<number>;
  lazyValueB: () => Promise<number>;
}

// Example usage
const userCallback: (input: Input) => Promise<number> = async ({lazyValueA, lazyValueB}) => {
  return (await lazyValueA()) + (await lazyValueB());
}

I have explored these paths but neither have been successful:
- model the Op return as an
Input
Input
struct with v8::Function fields (while returning v8::Function values is supported)
- model the Op return as an
Input
Input
as
Future
Future
values, but serializing Future is obviously problematic

Reading through the deno_ops and v8_serde packages, I don't see an obvious way to accomplish this (very open to thoughts about how to restructure this, feels like im working against the tooling here)
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How do you define an op in rust to return a string?
A Frickn ChicknAA Frickn Chickn / help
2y ago
Return results from execute_main_module
k-xoKk-xo / help
3y ago
KV: What to return from here?
Timo MartinsonTTimo Martinson / help
3y ago
HandleScope in async op
ExidexEExidex / help
3y ago