GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix deferred: adopting an already rejected promise never settles by Michael-Tot · Pull Request #179 · NutScript/NutScript

Conversation

@Michael-Tot

@Michael-Tot Michael-Tot commented Oct 30, 2026

Copy link
Copy Markdown

gamemode/core/libs/thirdparty/sh_deferred.lua (from brianhang/deferred-lua) never settles a chain when a step hands back a promise that is already rejected, e.g. return deferred.reject(err) from a :next() handler. Nothing downstream runs, no error is shown, and sometimes a misleading "Unhandled rejection" is printed even though a handler is attached.

deferred.resolve(1)
    :next(function() return deferred.reject("boom") end)
    :catch(function(err) print("caught", err) end) -- never runs

The adoption code copies the state first and then calls self:reject(), which does nothing once the state isn't pending. This PR applies the same four-line fix as upstream: brianhang/deferred-lua#1. That PR has the explanation, new tests, and a 3,000-chain differential check against the current version.

NutScript's own code doesn't return deferred.reject from handlers, so existing behaviour is unchanged. The only behaviour that changes is chains that used to hang. Schemas and plugins that ran into this can drop their workarounds. (We worked around it with a promise that rejects on the next tick.)

Checked on a GMod server with lua_openscript. With the current file, the repro chain return deferred.reject("boom") never settles, an "Unhandled rejection" error is printed even though a handler is attached, and the suite reports 56/60. With the patched file, everything settles and all 60 tests pass. The full output is in the upstream PR, and the tests and in-game check are at https://github.com/Michael-Tot/deferred-lua-tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TovarischPootis reacted with eyes emoji
All reactions
  • 👀 1 reaction
@Michael-Tot @claude
Fix deferred: adopting an already rejected promise never settles
2445468
Returning an already rejected promise (e.g. deferred.reject(err)) from a
:next() handler left the chain pending forever, and could print a false
"Unhandled rejection". Same fix as upstream brianhang/deferred-lua.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DgG3uPXXFXpfc6VxJ12P8R
@Michael-Tot

Michael-Tot commented Oct 30, 2026

Copy link
Copy Markdown
Author

also a small note, just from the human Michael, not with Claude's help: This problem haunted me personally, I resent it. I despise it. I wish it nothing but misery.

Pls fix!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Michael-Tot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.