Loading video player...
Είσαι έτοιμος να μετατρέψεις το Go Wasm module σου από απλό πρόγραμμα σε μια ισχυρή, επαναχρησιμοποιήσιμη βιβλιοθήκη; Σε αυτό το τρίτο μάθημα, κάνουμε την κρίσιμη μετάβαση από το μοντέλο Command στο Reactor Pattern, επιτρέποντας στο Host (π.χ. wazero) να καλεί συγκεκριμένες Go συναρτήσεις (ComputeScore) πολλές φορές! Θα εξερευνήσουμε: 🔄 Command vs. Reactor: Γιατί χρειαζόμαστε το Reactor pattern για μακροχρόνιες παρουσίες Wasm. 🏷️ Εξαγωγή Συνάρτησης: Η νέα οδηγία //go:wasmexport (Go 1.24+) και πώς εξάγουμε συναρτήσεις για κλήση από τον Host. 🧠 Linear Memory & Σύνθετοι Τύποι: Το κλειδί για τη μεταφορά δεδομένων! Πώς στέλνουμε σύνθετα δεδομένα (όπως JSON) στο Wasm, περνώντας μόνο διευθύνσεις (i32 pointer) και μήκη (i32 length) μέσω της γραμμικής μνήμης (Linear Memory). 🏗️ Μεταγλώττιση Reactor: Τι κάνει η κρίσιμη σημαία -buildmode=c-shared και γιατί παράγει τη συνάρτηση _initialize αντί για την _start. 🔢 Bits Across the Boundary: Κατανόηση γιατί επιστρέφουμε uint64 (το raw bit pattern) αντί για float64 και πώς το math.Float64FromBits χρησιμοποιείται για την ανάκτηση της τιμής στον Host. ---- Ready to transform your Go Wasm module from a simple program into a powerful, reusable library? In this third lesson, we make the critical shift from the Command model to the Reactor Pattern, allowing the Host (e.g., wazero) to call specific Go functions (ComputeScore) multiple times! We will explore: 🔄 Command vs. Reactor: Why we need the Reactor pattern for long-running Wasm instances. 🏷️ Function Exporting: The new //go:wasmexport directive (Go 1.24+) and how we expose functions for the Host to call. 🧠 Linear Memory & Complex Types: The key to data transfer! How we send complex data (like JSON) into Wasm by only passing pointers (i32 address) and lengths (i32 len) via Linear Memory. 🏗️ Reactor Compilation: What the critical flag -buildmode=c-shared does and why it generates the _initialize function instead of _start. 🔢 Bits Across the Boundary: Understanding why we return a uint64 (the raw bit pattern) instead of a float64, and how math.Float64FromBits is used on the Host to recover the value.