-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from axiomhq/support-web-workers
Support webworkers
- Loading branch information
Showing
12 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client' | ||
import { useEffect, useRef, useCallback } from 'react' | ||
import styles from '../page.module.css'; | ||
|
||
export default function WorkerPage() { | ||
const workerRef = useRef<Worker>() | ||
|
||
useEffect(() => { | ||
workerRef.current = new Worker(new URL('../../worker.ts', import.meta.url)) | ||
workerRef.current.onmessage = (event: MessageEvent<number>) => | ||
alert(`WebWorker Response => ${event.data}`) | ||
return () => { | ||
workerRef.current?.terminate() | ||
} | ||
}, []) | ||
|
||
const handleWork = useCallback(async () => { | ||
workerRef.current?.postMessage(100000) | ||
}, []) | ||
|
||
return ( | ||
<main className={styles.main}> | ||
<p>Do work in a WebWorker!</p> | ||
<button onClick={handleWork}>Send Logs to Axiom</button> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// This is a module worker, so we can use imports (in the browser too!) | ||
import { log } from 'next-axiom'; | ||
|
||
addEventListener('message', async (event: MessageEvent<number>) => { | ||
log.info("fired from worker") | ||
log.info(event.data.toString()) | ||
await log.flush() | ||
postMessage('done') | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b85adae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-axiom-example – ./
next-axiom-example-git-main.axiom.dev
next-axiom-example-lemon.vercel.app
next-axiom-example.axiom.dev