All Projects → devsnek → proposal-symbol-thenable

devsnek / proposal-symbol-thenable

Licence: other
gus.host/proposal-symbol-thenable

Programming Languages

HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to proposal-symbol-thenable

kubeswitch
visually select kubernetes context/namespace from tree
Stars: ✭ 15 (-16.67%)
Mutual labels:  namespace
vue-promise-dialogs
A tiny & modern library that allows you to work with dialogs as with asynchronous functions.
Stars: ✭ 43 (+138.89%)
Mutual labels:  promises
PackageProject.cmake
🏛️ Help other developers use your project. A CMake script for packaging C/C++ projects for simple project installation while employing best-practices for maximum compatibility.
Stars: ✭ 48 (+166.67%)
Mutual labels:  namespace
kube-watch
Simple tool to get webhooks on Kubernetes cluster events
Stars: ✭ 21 (+16.67%)
Mutual labels:  namespace
locize-cli
locize cli to import / export locales, add / edit / remove sync segments
Stars: ✭ 44 (+144.44%)
Mutual labels:  namespace
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (+11.11%)
Mutual labels:  promises
redux-reducer-async
Create redux reducers for async behaviors of multiple actions.
Stars: ✭ 14 (-22.22%)
Mutual labels:  promises
swift-futures
Demand-driven asynchronous programming in Swift
Stars: ✭ 32 (+77.78%)
Mutual labels:  promises
tsubaki
💮 Promisify with native promises
Stars: ✭ 18 (+0%)
Mutual labels:  promises
Javascript-Interview-Preparation
A curated collection of javascript interview questions & solutions.
Stars: ✭ 163 (+805.56%)
Mutual labels:  promises
NamingThings
Content on tips, tricks, advice, practices for naming things in in software/technology
Stars: ✭ 31 (+72.22%)
Mutual labels:  namespace
node-pagerduty
⛔️ DEPRECATED - PagerDuty v2 API Wrapper for Node
Stars: ✭ 19 (+5.56%)
Mutual labels:  promises
async-airtable
A lightweight npm package to handle working with the Airtable API.
Stars: ✭ 48 (+166.67%)
Mutual labels:  promises
storage
Extend the Chrome Extension Storage API with Promises and great TypeScript support.
Stars: ✭ 48 (+166.67%)
Mutual labels:  promises
proposal-function-helpers
A withdrawn proposal for standardizing some useful, popular helper functions into JavaScript’s Function object.
Stars: ✭ 41 (+127.78%)
Mutual labels:  tc39
tears
A particularly clean blog base on bottle and mongoDB
Stars: ✭ 15 (-16.67%)
Mutual labels:  tears
Microfutures
Lightweight implementation of Futures that shares a similar subscription interface with RxSwift.
Stars: ✭ 38 (+111.11%)
Mutual labels:  promises
lxroot
A lightweight, flexible, and safer alternative to chroot and/or Docker.
Stars: ✭ 69 (+283.33%)
Mutual labels:  namespace
flush-promises
Flush all queued resolved promise handlers
Stars: ✭ 172 (+855.56%)
Mutual labels:  promises
phaser-super-storage
A cross platform storage plugin for Phaser
Stars: ✭ 49 (+172.22%)
Mutual labels:  namespace

Symbol.thenable

Champions: Myles Borins, Jordan Harband

Author: Gus Caplan

Stage 0

Why

The behaviour of Promise.resolve includes checking for then functions on whatever you pass it. This allows interop with legacy third-party Promise implementation protocols, and in most cases does not result in any issues, but there remain scenarios where it is unwanted.

This is especially true with dynamic import of module namespace objects, which will become part of the language spec very soon. A namespace might be interpreted as a "thenable" resulting in a non-namespace return from import() - which may be very unexpected. There has been a lot of previous discussion around these scenarios, including tc39/proposal-dynamic-import#47 and tc39/proposal-dynamic-import#48.

import * as static from 'X'

import('X').then((dynamic) => {
  assert(static === dynamic); // might be false, /hopefully/ the consumer of X
                              // and the author of X are both aware of this
                              // behaviour (and if they are, no one exploits
                              // it to do confusing things)
});

Proposal

The natural conclusion of this is to add some sort of modifier to an object such that Promise.resolve is aware that it should not perform "thenable" behaviour.

Enter: Symbol.thenable

Promise.resolve({
  [Symbol.thenable]: false,
  then() { return 'a time that isn\'t now'; },
}).then((o) => {
  o.then() === 'a time that isn\'t now';
});

In addition this symbol would be set by default on Module Namespace objects. While users can already import * a namespace object and return it through a promise resolution, this can still be considered an incredibly rare case today.

This came from trying to think of the most generalised solution to this problem. Alternatives could include explicitly blacklisting a Module Namespace Object in Promise.resolve, however there was resistance to this, as it might not be entirely intuitive why this object was being treated differently. Symbol.thenable provides clear explanation for that.

In the future, this symbol can also be used by a protocol (see the First-Class Protocols Proposal) along the lines of Promise.Thenable as a sort of "disabled" symbol.

Alternatives and Options

  • Mount symbol on Promise namespace (Promise.thenable)

  • Whitelist specific objects we don't want to treat as "thenables":

    1. If _resolution_ is a Module Namespace Object, then
      1. Return FulfullPromise(_promise_, _resolution_).
    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].