Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Implementing a Promise Class
00:00
5 left

Implementing a Promise Class

HardPython

Problem

Write promise class from scratch.

Implement a Python function that defines and exercises a Promise-like abstraction. It must support fulfillment, rejection, chaining with then, exception propagation, thenable assimilation, self-resolution protection, finally, and the all and race combinators.

Use the supplied scenario object as the grading contract. Return a plain dictionary containing the final state and either value or the exception type in error.

Function signature: def promise_class(scenario):

Constraints

  • scenario is a JSON-compatible dictionary with a valid kind field
  • chain operations contain only map, throw, or reject operations
  • all and race values are JSON-compatible primitive values
  • Promise settlement is one-way
  • The returned dictionary must contain only JSON-compatible values

Function Signature

def promise_class(scenario):
Interviewer

Your question is Implementing a Promise Class. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.