| 1014 | { |
| 1015 | expected: "AsyncResult", |
| 1016 | toCodec([value, cause]) { |
| 1017 | const Success = Schema_.TaggedStruct("Success", { value, waiting: Schema_.Boolean, timestamp: Schema_.Int }) |
| 1018 | return Schema_.link<AsyncResult<A["Encoded"], E["Encoded"]>>()( |
| 1019 | Schema_.Union([ |
| 1020 | Schema_.TaggedStruct("Initial", { waiting: Schema_.Boolean }), |
| 1021 | Success, |
| 1022 | Schema_.TaggedStruct("Failure", { |
| 1023 | cause, |
| 1024 | previousSuccess: Schema_.Option(Success), |
| 1025 | waiting: Schema_.Boolean |
| 1026 | }) |
| 1027 | ]), |
| 1028 | SchemaTransformation.transform({ |
| 1029 | decode: (encoded): AsyncResult<A["Encoded"], E["Encoded"]> => { |
| 1030 | switch (encoded._tag) { |
| 1031 | case "Initial": |
| 1032 | return initial(encoded.waiting) |
| 1033 | case "Success": |
| 1034 | return success(encoded.value, { |
| 1035 | waiting: encoded.waiting, |
| 1036 | timestamp: encoded.timestamp |
| 1037 | }) |
| 1038 | case "Failure": { |
| 1039 | return failure(encoded.cause, { |
| 1040 | previousSuccess: Option.map(encoded.previousSuccess, (ps) => success(ps.value, ps)), |
| 1041 | waiting: encoded.waiting |
| 1042 | }) |
| 1043 | } |
| 1044 | } |
| 1045 | }, |
| 1046 | encode(result) { |
| 1047 | switch (result._tag) { |
| 1048 | case "Initial": |
| 1049 | return { _tag: "Initial" as const, waiting: result.waiting } |
| 1050 | case "Success": |
| 1051 | return { |
| 1052 | _tag: "Success" as const, |
| 1053 | value: result.value, |
| 1054 | waiting: result.waiting, |
| 1055 | timestamp: result.timestamp |
| 1056 | } |
| 1057 | case "Failure": |
| 1058 | return { |
| 1059 | _tag: "Failure" as const, |
| 1060 | cause: result.cause, |
| 1061 | previousSuccess: result.previousSuccess, |
| 1062 | waiting: result.waiting |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | }) |
| 1067 | ) |
| 1068 | }, |
| 1069 | toEquivalence: Equal.asEquivalence, |
| 1070 | toFormatter: ([value, cause]) => (t) => { |
| 1071 | switch (t._tag) { |