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.

stop() returning a promise and not decorating the server

See original GitHub issue

I’m curious whether folks are interested in revisiting some of the design decisions.

For one it’d be interesting if stoppable() could return the stop() function, rather than assigning it to the server value. Calling code could still do server.stop = stoppable(server). Personally I don’t find the chaining argument convincing.

It’d also be neat if stop() would return a promise, rather than taking a callback. It wouldn’t match the server.close() API but in these glorious days of async / await I think returning a promise would be more usable.

Once stop() no longer takes a callback it’d be possible to pass grace directly.

These last two changes combined make it possible to use stoppable with https://www.npmjs.com/package/@digicat/termination-manager (which, full disclaimer, I wrote). That library can vary the grace period based on whether the process is crashing or merely terminating, which doesn’t work with stoppable as-is.

If folks disagree I’m happy to publish a fork elsewhere but I figured I’d ask first. These nits aside stoppable is the nicest library I’ve found for stopping servers 🥇

Thanks for reading this far!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

1reaction
boneskullcommented, Nov 10, 2018

I would rather not change the API of stop, as returning a Promise when the callback is missing implies stuff about exception handling that may shock users who are calling stop() without the (optional) callback.

How about just adding stopAsync()?

0reactions
pimterrycommented, Oct 11, 2019

I’d appreciate promises here too. Almost all my code is promises & async/await now, so the callback here is a bit awkward. I’d prefer to just make the callback optional on stop(), and return a promise if it’s not provided. It seems that that’s what most other libraries have done, but either option would be a nice improvement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

return does not terminate a promise/then chain - Stack Overflow
The return ends the current function that is running, which is not the promise chain. So this part: return resolved(false); //SHOULD STOP + ......
Read more >
Decorating Async JavaScript Functions - Innolitics
In this article, we explore how to extend async JavaScript functions using a functional design pattern—the decorator.
Read more >
async function - JavaScript - MDN Web Docs - Mozilla
An async function will return a different reference, whereas Promise.resolve returns the same reference if the given value is a promise. It can ......
Read more >
21.1.0 API Reference - hapi.dev
If the server is never stopped, or if it is forced to stop without waiting ... The object must not be modified directly,...
Read more >
$http - AngularJS: API
The next time the same request is made, the response is returned from the cache without sending a request to the server. Take...
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