await tuple(promise) 는 던지는 대신 배열을 돌려준다. 성공하면 [null, 결과], 실패하면 [error]. reject 된 값이 Error 가 아니면(문자열·undefined 등) TupleItError 로 감싸서, if (error) 하나로 성공과 실패가 갈린다. try…catch 대신 쓰는 이 모양을 언어 문법으로 넣자는 제안이 safe assignment operator 다.

-- 비동기 결과와 오류를 튜플로 — try…catch 대신
tuple :: IO a -> IO (Either Error a)
tuple p = (Right <$> p) `catch` (pure . Left . wrap)
  where wrap e | isError e = e
               | otherwise = TupleItError e   -- Error 가 아닌 값으로 reject 돼도 감싼다

-- const [error, data] = await tuple(someAsyncFunction())
--   성공 [null, data] · 실패 [error] — if (error) 하나로 갈린다
-- 언어 문법으로 넣자는 제안: safe assignment operator (?=)

출처

`#357`