Comments (8)
Maybe @MaxGraey would be the one to ask here :)
from wasi-experimental-http.
сс @dcodeIO
from wasi-experimental-http.
Finalization should happen eventually, once the GC kicks in. With the incremental runtime, when this happens depends, though. With default settings, the first threshold is at about half the memory used for example, so depending on the program's allocation pattern, the GC may kick in early, or even never. Subsequent GCs happen when used memory doubles again, relative to remaining memory used after the previous collection. Probably not good enough to rely upon for closing handles.
from wasi-experimental-http.
Thanks a lot for your reply, @dcodeIO!
I guess we have to keep the requirement that consumers have to manually close the handle for now, until we have a better solution, such as a destructor.
from wasi-experimental-http.
That issue is common to virtual alll WASI APIs, that heavily depend on handles.
In Zig, instead of finalizers, we have defer
and errdefer
statements that can automatically free a resource before a function returns, or on error.
Maybe this is something that could also be implemented in AssemblyScript?
from wasi-experimental-http.
defer
is just early declaration for releasing resource (explicit RAII) and this the same as manually close such resource before return but with some more continent way. So
fn foo() -> bool {
let res = io.open(path)
defer(res)
// some code
if (fail) return false // will implicitly call io.close(res) before return. Injected in compile time
// some other code
return true // will implicitly call io.close(res) before return
}
and it's the same as:
fn foo() -> bool {
let res = io.open(path)
// some code
if (fail) {
io.close(res)
return false
}
// some other code
io.close(res)
return true
}
and this works only inside user space
from wasi-experimental-http.
JavaScript / Typescript usually return callback function which contine code for finalization:
export function foo(): () => bool {
const desc = fs.open(path);
// some code
return () => {
fs.close(desc);
return true;
};
}
while AS don't support closures. It may be temporary workaround:
let tmpDesc: FileDesc | null = null; // global var
export function foo(): () => bool {
tmpDesc = fs.open(path); // store to global desc
// some code
return () => {
fs.close(tmpDesc); // reat from global desc
return true;
};
}
from wasi-experimental-http.
If you required many descriptors simultaneously it may be something like this:
let descMap: Map<i32, FileDesc> = new Map; // it could be stack / queue
let gId = 0;
export function foo(): (id: i32) => bool {
descMap.set(gId++, fs.open(path)); // store to global desc
// some code
return (id: i32) => {
if (descMap.has(id)) {
let desc = descMap.get(id);
fs.close(desc); // reat from global desc
descMap.delete(id);
return true;
}
return false;
};
}
from wasi-experimental-http.
Related Issues (20)
- Support wasmtime 4.0
- unknown import: `wasi_experimental_http::req` has not been defined
- Options HOT 1
- AssemblyScript: `Console.log` of string literal panics HOT 2
- Implement host call to get all headers
- Add a simple binary that can be used for standalone testing modules
- Failing tests related to allowed hosts in AssemblyScript HOT 2
- Destination not allowed"
- "Destination not allowed" errors are non-descriptive
- Server Support HOT 2
- Compiling anything that imports `wasi_experimental_http_wasmtime` fails on Windows HOT 1
- Update Wasmtime to v0.28
- Explore re-building on top of WITX2 and `witx-bindgen`
- Automate package publishing
- HTTP endpoint used in tests changed
- Check origin as opposed to only the host
- Add TinyGo client implementation HOT 1
- Update `as-wasi` dependency in AssemblyScript client HOT 1
- Cargo.toml wasi-experimental-http and wasi-experimental-http-wasmtime dependencies: crates.io vs local path?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasi-experimental-http.