~technomancy/fennel

Improving the REPL loading feedback v1 PROPOSED

gbaptista: 1
 Improving the REPL loading feedback

 1 files changed, 16 insertions(+), 11 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~technomancy/fennel/patches/12075/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Improving the REPL loading feedback Export this patch

Hi!

This patch improves user feedback when loading the repl.

I found that the problem is related to how the Javascript Event Loop works. The talk "What the heck is the event loop anyway?" by Philip Roberts was a joy of knowledge!

This patch does not solve the entire problem: The fact that the browser still freezes during the loading and the page does not respond until the repl is loaded makes me crazy.
I will try to do some experiments, and if it works, I send a second patch. Probably some solution using js async feature or Web Workers will do the trick.
---
 init.lua | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/init.lua b/init.lua
index a55516e..94fbc55 100644
--- a/init.lua
+++ b/init.lua
@@ -126,17 +126,22 @@ local repl
-- loading Fennel at the top level breaks scrolling because browsers
-- are terrible; so we load when the input element gets focus
function input.onfocus()
   -- setting input.onfocus to nil has no effect, somehow
   if repl ~= nil then return end
   _G.print("Loading...")
   local fennel = require("fennel/fennel")
   package.loaded.fennel = fennel
   repl = coroutine.create(fennel.dofile("repl.fnl"))
   assert(coroutine.resume(repl))
   welcome = "Welcome to Fennel " .. fennel.version ..
      ", running on Fengari (" .. _VERSION .. ")"
   _G.print(welcome)
   _G.printLuacode("Compiled Lua code")
    -- setting input.onfocus to nil has no effect, somehow
    if repl ~= nil then return end
    _G.print("Loading Fennel...")
    js.global:setTimeout(function()
        local fennel = require("fennel/fennel")
       package.loaded.fennel = fennel
       _G.print("Loading REPL...")
       js.global:setTimeout(function()
           repl = coroutine.create(fennel.dofile("repl.fnl"))
           assert(coroutine.resume(repl))
           welcome = "Welcome to Fennel " .. fennel.version ..
              ", running on Fengari (" .. _VERSION .. ")"
           _G.print(welcome)
           _G.printLuacode("Compiled Lua code")
        end)
    end)
end

function input.onkeydown(_, e)
-- 
2.28.0
gbaptista <gbaptistas@protonmail.com> writes: