question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event loop implementation?

See original GitHub issue

This has come up at least a couple times in different contexts and I think this would be a cool idea with some interesting applications. Plus @keynmol may have volunteered himself to take this on 😉

Why:

  • JVM: IO#unsafeRunSync in single-threaded environments (e.g. AWS lambda) without the penalty of creating threads or shifting.
  • JS: unsafeRunSync (!!) via a new “TemporalSyncIO” data type that implements Temporal and Sync. @djspiewak pointed out this would be similar to the microtask loop (with the addition of timers).
  • Native: when Native rolls around, IIUC this should give us a single-threaded runtime essentially for free.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
armanbilgecommented, Feb 27, 2022

@ritschwumm actually it seems like it is already possible to run tasks on the AWT event dispatch thread without any changes in CE.

I see there is a method SwingUtilities.doLater that causes a Runnable “to be executed asynchronously on the AWT event dispatching thread.”

So all you need is something like:

object AwtEventDispatchEC extends ExecutionContext {
  def execute(r: Runnable): Unit = SwingUtilities.doLater(r)
  def reportFailure(t: Throwable): Unit = t.printStackTrace()
}

IO(whatever).evalOn(AwtEventDispatchEC)

Since the main thread is special, it requires the changes proposed in https://github.com/typelevel/cats-effect/pull/2732.

1reaction
ritschwummcommented, Jan 7, 2022

@bilki it’s not just the main thread, with e.g. AWT (and by extension, swing) you sometimes need to run things synchronously in the event dispatch thread

Read more comments on GitHub >

github_iconTop Results From Across the Web

Explaining event loop in 100 lines of code - iximiuz
In the article, I'll try to describe the idea of the event loop in general, not a specific implementation of the event loop...
Read more >
The event loop - JavaScript - MDN Web Docs - Mozilla
JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, ...
Read more >
Event Loop — Python 3.11.1 documentation
The event loop is the core of every asyncio application. Event loops run asynchronous tasks and callbacks, perform network IO operations, and run...
Read more >
How would you implement a basic event-loop? - Stack Overflow
First we need a thread safe queue which allow multiple producers and at least a single consumer (the EventLoop thread). The EventLoop object ......
Read more >
A Visual Explanation of JavaScript Event Loop
In this tutorial, you will learn about the event loop in JavaScript and how JavaScript achieves the concurrency model based on the event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found