A simple demo that shows how WebWorkers can be used in Kotlin/JS

Overview

Web Workers in KotlinJS

This repo demonstrates how to set up a Web Worker in Kotlin/JS. It is a very simple demo that creates a new worker that sends back the current time.

Check out the live demo!

How does it work?

By setting up an additional compilation target so that two separate .js files will be generated. The client code (which runs in the main execution thread) can then spawn a worker that executes the worker code.

This allows us to share the commonMain code between both client and worker, without requiring the worker to have all the client code (and vice versa). This "separation of concerns" makes the code simpler and helps keep file sizes low.

Limitations

The jsBrowserRun tasks currently don't work because (I think) webpack isn't serving the worker code. I think this can be fixed with a little gradle magic but I haven't got it figured out yet.

Running the built files locally is just a tiny bit more difficult than usual because you can't just open index.html and have everything work; the worker.js script is blocked because of security things. The simple workaround is to run an http server in that dir. For example, with python you can

cd build/distributions && python -m http.server

and then open your browser to the port it's hosting on (probably localhost:8000)

You might also like...
Most used extension methods for Kotlin

Extensify Most used extension methods for Kotlin Download Step 1. Add the JitPack repository to your build file allprojects { repositories {

Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.
Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.

Klimatic Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android. Built using Android Architectu

This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS lambda function using the custom runtime.
This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS lambda function using the custom runtime.

Overview This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS Lambda function using a custom runtime. U

Theia - A Kotlin program used to analyze and discover backdoors in Minecraft Java 1.12.2 forge mods

Theia A Kotlin program used to analyse and discover backdoors in Minecraft Java

Kotools Types - a lightweight library that provides commonly used types for Kotlin

Kotools Types is a lightweight library that provides commonly used types for Kotlin

Simple Design for Kotlin bridge with Javascript. Also can get javascript console.log.
Simple Design for Kotlin bridge with Javascript. Also can get javascript console.log.

SDBridgeJava is here. If your h5 partner confused about how to deal with iOS and Android. This Demo maybe help. bilibili video introduction is here. Y

:octocat: A demo project based on MVVM architecture and material design & animations.
:octocat: A demo project based on MVVM architecture and material design & animations.

GithubFollows A simple demo project based on MVVM clean architecture and material design & animations. Architecture Specs & Open-source libraries Mini

Course_modularizing_android_apps - Multi-module demo app that gets data from a Dota2 api
Course_modularizing_android_apps - Multi-module demo app that gets data from a Dota2 api

Work in progress Multi-module demo app that gets data from a Dota2 api. Module n

This is a demo android app representing implementation of SE principles in android app development

Articles Demo This repository contains a sample Android App that shows most popular articles data from NY Times API. This is a sample app that shows h

Add status to beans in Compose, Fields in beans can be directly used as the MutableState

Buff Add status to beans in Jetpack(jb) Compose, Fields in beans can be directly used as the MutableState<T> ⚠️ Non mainstream warning:This item viola

lt 2 Oct 23, 2022
AsyncSport - AsyncSports Async sports is very simple application that shows athletes video feeds

AsyncLabs Interview Solution ?? Writing AsyncLabs Interview Solution App using A

David Innocent 0 Jan 7, 2022
This sample Kotlin app shows a list of custom shoes added by the users

Shoe-store This sample Kotlin app shows a list of custom shoes added by the users. The app displays the content with RecyclerView and uses a tradition

Ana Stanescu 2 Aug 27, 2022
Dots indicator that shows the current position on a View Pager. It does all the work for you with a few customisations.

Dots What is Dots? Dots is a library that helps in implementing a simple yet effective dots indicator for the View Pagers used in your android code. I

Deepan 23 Feb 16, 2022
Sample project that shows an approach for designing a multi-module architecture for Jetpack Compose Android applications.

Compose Multi-Module Architecture Sample Sample project that shows an approach for designing a multi-module architecture for Jetpack Compose Android a

Pavlo Stavytskyi 77 Jan 3, 2023
A native android app that shows how much calories one must consume based on their profile

Healtify is a native android app which allows the user to track the amout of Calories they are consuming. It not only tracks the calories but also shows how much of fat, protein and carbs they have consumed and how much they should be doing.

Anindya Ray 9 Aug 20, 2022
Cinemax is a Movies & TV Shows application for Android.

Cinemax Cinemax is a Movies & TV Shows application for Android. Build Generate an API key from The Movie Database. Put the key in the local.properties

Maximillian Leonov 40 Jan 1, 2023
🎬 A demo project for The Movie DB based on Kotlin MVVM architecture and material design & animations.

TheMovies A simple project for The Movie DB based on Kotlin MVVM clean architecture and material design & animations. How to build on your environment

Jaewoong Eum 419 Jan 7, 2023
Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures

CatViewerDemo Android demo iOS demo Kotlin Multiplatform Mobile demo for Android and iOS. App for viewing Cat pictures from Cats API. This sample show

Martin Rajniak 111 Dec 18, 2022