justforfunc | The repository for the YouTube series JustForFunc
kandi X-RAY | justforfunc Summary
kandi X-RAY | justforfunc Summary
This repository contains the code for most of the episodes from the YouTube series #justforfunc.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of justforfunc
justforfunc Key Features
justforfunc Examples and Code Snippets
Community Discussions
Trending Discussions on justforfunc
QUESTION
I wrote a small checkbook ledger in Go as a server that runs in localhost and opens the default browser to a small web app front-end (https://bitbucket.org/grkuntzmd/checks-and-balances).
To automatically shut down the server when the browser tab is closed, I have the browser call a "heartbeat" URL every few seconds. If that heartbeat does not arrive, the server uses (*Server) Shutdown
to stop running.
Is there any way to do the same thing using contexts (https://golang.org/pkg/context/)? It is my understanding from watching this episode of JustForFunc that a context passed down to a handler will be notified if the client cancels a request.
...ANSWER
Answered 2018-Jun-04 at 19:33Instead of sending a "heartbeat" request every so often, you could take advantage of server-sent events.
Server-sent events is a web technology where the browser makes a HTTP request and keeps the connection open to receive events from the server. This could replace your need for repeated heartbeat requests by having the server shutdown when the connection to the event source is closed.
Here's a basic server implementation in Go:
QUESTION
I was following tutorial from JustForFunc episode 22
Added those two lines at the start of main() in main.go:
...ANSWER
Answered 2017-Nov-11 at 12:02I found a solution to my problem. I followed this tutorial https://making.pusher.com/go-tool-trace/. Added code to main :
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install justforfunc
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page